From 415dcebedeb4755b50f6e15c8a2ab73592919307 Mon Sep 17 00:00:00 2001 From: huanghua Date: Thu, 28 Sep 2006 07:18:40 +0000 Subject: [PATCH] remove dir entry in *OBJ_TEMP* while deleting file (also as a hack). --- lustre/mdt/mdt_open.c | 5 ++--- lustre/osd/osd_handler.c | 45 +++++++++++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/lustre/mdt/mdt_open.c b/lustre/mdt/mdt_open.c index f015fa3..610d9dd 100644 --- a/lustre/mdt/mdt_open.c +++ b/lustre/mdt/mdt_open.c @@ -122,7 +122,7 @@ int mdt_epoch_open(struct mdt_thread_info *info, struct mdt_object *o, { struct mdt_device *mdt = info->mti_mdt; int cancel = 0; - int rc; + int rc = 0; ENTRY; if (!S_ISREG(lu_object_attr(&o->mot_obj.mo_lu))) @@ -153,9 +153,8 @@ int mdt_epoch_open(struct mdt_thread_info *info, struct mdt_object *o, lh->mlh_mode = LCK_EX; rc = mdt_object_lock(info, o, lh, MDS_INODELOCK_UPDATE); mdt_object_unlock(info, o, lh, 1); - RETURN(rc); } - RETURN(0); + RETURN(rc); } /* Update the on-disk attributes if needed and re-enable Size-on-MDS caching. */ diff --git a/lustre/osd/osd_handler.c b/lustre/osd/osd_handler.c index 7b95d45..3bed1c8 100644 --- a/lustre/osd/osd_handler.c +++ b/lustre/osd/osd_handler.c @@ -273,6 +273,13 @@ static int osd_write_locked(const struct lu_context *ctx, struct osd_object *o) return oti->oti_w_locks > 0 && o->oo_owner == ctx; } +static void osd_fid_build_name(const struct lu_fid *fid, char *name) +{ + static const char *qfmt = LPX64":%lx:%lx"; + + sprintf(name, qfmt, fid_seq(fid), fid_oid(fid), fid_ver(fid)); +} + /* helper to push us into KERNEL_DS context */ static struct file *osd_rw_init(const struct lu_context *ctxt, struct inode *inode, mm_segment_t *seg) @@ -387,26 +394,47 @@ static int osd_inode_unlinked(const struct inode *inode) } enum { - OSD_TXN_OI_DELETE_CREDITS = 20 + OSD_TXN_OI_DELETE_CREDITS = 20, + OSD_TXN_RMENTRY_CREDITS = 20 }; static int osd_inode_remove(const struct lu_context *ctx, struct osd_object *obj) { + const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu); struct osd_device *osd = osd_obj2dev(obj); struct osd_thread_info *oti = lu_context_key_get(ctx, &osd_key); struct txn_param *prm = &oti->oti_txn; struct thandle *th; + struct dentry *dentry; int result; - prm->tp_credits = OSD_TXN_OI_DELETE_CREDITS; + prm->tp_credits = OSD_TXN_OI_DELETE_CREDITS + OSD_TXN_RMENTRY_CREDITS; th = osd_trans_start(ctx, &osd->od_dt_dev, prm); if (!IS_ERR(th)) { osd_oi_write_lock(&osd->od_oi); - result = osd_oi_delete(oti, &osd->od_oi, - lu_object_fid(&obj->oo_dt.do_lu), th); - iput(obj->oo_inode); + result = osd_oi_delete(oti, &osd->od_oi, fid, th); osd_oi_write_unlock(&osd->od_oi); + + /* + * The following is added by huanghua@clusterfs.com as + * a temporary hack, to remove the directory entry in + * "*OBJ_TEMP*". We will finally do not use this hack, + * and at that time we will remove these code. + */ + osd_fid_build_name(fid, oti->oti_name); + oti->oti_str.name = oti->oti_name; + oti->oti_str.len = strlen(oti->oti_name); + + dentry = d_alloc(osd->od_obj_area, &oti->oti_str); + if (dentry != NULL) { + struct inode *dir = osd->od_obj_area->d_inode; + obj->oo_inode->i_nlink = 1; + d_instantiate(dentry, obj->oo_inode); + result = dir->i_op->unlink(dir, dentry); + dput(dentry); + } else + iput(obj->oo_inode); osd_trans_stop(ctx, th); } else result = PTR_ERR(th); @@ -820,13 +848,6 @@ static int osd_create_post(struct osd_thread_info *info, struct osd_object *obj, return 0; } -static void osd_fid_build_name(const struct lu_fid *fid, char *name) -{ - static const char *qfmt = LPX64":%lx:%lx"; - - sprintf(name, qfmt, fid_seq(fid), fid_oid(fid), fid_ver(fid)); -} - static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj, umode_t mode, struct thandle *th) { -- 1.8.3.1