From: Fan Yong Date: Sun, 20 Oct 2013 15:07:27 +0000 (+0800) Subject: LU-3335 osd: use local transaction directly inside OSD X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=3e09d632405914ed188e40b7e5759aa1f740c361;p=fs%2Flustre-release.git 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 --- diff --git a/lustre/osd-ldiskfs/osd_compat.c b/lustre/osd-ldiskfs/osd_compat.c index f7fbe79..52694dd 100644 --- a/lustre/osd-ldiskfs/osd_compat.c +++ b/lustre/osd-ldiskfs/osd_compat.c @@ -531,10 +531,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; @@ -546,9 +545,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; @@ -609,12 +607,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); @@ -627,19 +625,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; @@ -654,7 +650,7 @@ static int osd_obj_del_entry(struct osd_thread_info *info, rc = -ENOENT; bh = osd_ldiskfs_find_entry(dir, child, &de, 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); @@ -666,9 +662,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; @@ -678,9 +673,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); @@ -699,7 +693,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); @@ -936,7 +930,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; @@ -979,7 +973,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; @@ -1013,7 +1007,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; @@ -1118,28 +1112,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, &de, - 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); } @@ -1192,7 +1175,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; @@ -1213,7 +1196,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 b479ea8..5a011f2 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -2212,16 +2212,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, @@ -2428,7 +2432,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 c460421..f2836da 100644 --- a/lustre/osd-ldiskfs/osd_internal.h +++ b/lustre/osd-ldiskfs/osd_internal.h @@ -655,12 +655,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); @@ -668,10 +668,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 a7d8581..cc69fe28 100644 --- a/lustre/osd-ldiskfs/osd_oi.c +++ b/lustre/osd-ldiskfs/osd_oi.c @@ -562,11 +562,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; @@ -579,14 +578,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)); @@ -595,7 +593,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; @@ -668,36 +666,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; @@ -718,7 +714,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 2658feb..dcdb744 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; }