From a02fd4573fea82b30a9e2f294d871110f6017ee3 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Thu, 14 Dec 2017 14:53:58 -0700 Subject: [PATCH] LU-7787 mdd: clean up orphan object handling There was a potential problem in the orphan object naming because it had an embedded space in the filename before the "operation", which might cause issues if they are accessed for other reasons. It turns out that there is no need for the "operation" to be embedded into the filename, since it was always ORPH_OP_UNLINK. Use standard DFID formatting for the orphan object names, which is a bit shorter and more efficient on disk, without the embedded operation type. Remove the use of "ORPH_OP_UNLINK" in the code, except in the compatibility code for handling orphans left over after upgrades from older Lustre versions. This can be removed at some point in the future when there are no longer upgrades from pre-2.11 versions. Signed-off-by: Andreas Dilger Change-Id: Ica90cc03c3212103c39cba11c4566584bf9cab07 --- lustre/mdd/mdd_orphans.c | 160 +++++++++++++++++++++++------------------------ 1 file changed, 77 insertions(+), 83 deletions(-) diff --git a/lustre/mdd/mdd_orphans.c b/lustre/mdd/mdd_orphans.c index 08f5846..3e726cc 100644 --- a/lustre/mdd/mdd_orphans.c +++ b/lustre/mdd/mdd_orphans.c @@ -49,42 +49,40 @@ const char orph_index_name[] = "PENDING"; static const char dotdot[] = ".."; enum { - ORPH_OP_UNLINK, - ORPH_OP_TRUNCATE + ORPH_OP_UNLINK, }; -#define ORPHAN_FILE_NAME_FORMAT "%016llx:%08x:%08x:%2x" -#define ORPHAN_FILE_NAME_FORMAT_18 "%llx:%08x" +/* obsolete after 2.11, needed for upgrades from older 2.x versions */ +#define ORPHAN_FILE_NAME_FORMAT_20 "%016llx:%08x:%08x:%2x" -static struct dt_key* orph_key_fill(const struct lu_env *env, - const struct lu_fid *lf, __u32 op) +static struct dt_key *orph_key_fill(const struct lu_env *env, + const struct lu_fid *lf) { char *key = mdd_env_info(env)->mti_key; - int rc; - - LASSERT(key); - rc = snprintf(key, NAME_MAX + 1, ORPHAN_FILE_NAME_FORMAT, - (long long unsigned int)fid_seq(lf), - fid_oid(lf), fid_ver(lf), op); - if (rc > 0) - return (struct dt_key*) key; - else - return ERR_PTR(rc); + int rc; + + LASSERT(key); + rc = snprintf(key, NAME_MAX + 1, DFID_NOBRACE, PFID(lf)); + if (rc > 0) + return (struct dt_key *)key; + + return ERR_PTR(rc); } -static struct dt_key* orph_key_fill_18(const struct lu_env *env, - const struct lu_fid *lf) +/* compatibility with orphan files created in versions before 2.11 */ +static struct dt_key *orph_key_fill_20(const struct lu_env *env, + const struct lu_fid *lf) { char *key = mdd_env_info(env)->mti_key; - int rc; - - LASSERT(key); - rc = snprintf(key, NAME_MAX + 1, ORPHAN_FILE_NAME_FORMAT_18, - (unsigned long long)fid_seq(lf), fid_oid(lf)); - if (rc > 0) - return (struct dt_key*) key; - else - return ERR_PTR(rc); + int rc; + + LASSERT(key); + rc = snprintf(key, NAME_MAX + 1, ORPHAN_FILE_NAME_FORMAT_20, + fid_seq(lf), fid_oid(lf), fid_ver(lf), ORPH_OP_UNLINK); + if (rc > 0) + return (struct dt_key *)key; + + return ERR_PTR(rc); } static inline void mdd_orphan_write_lock(const struct lu_env *env, @@ -144,16 +142,15 @@ static inline int mdd_orphan_ref_del(const struct lu_env *env, } -int orph_declare_index_insert(const struct lu_env *env, - struct mdd_object *obj, +int orph_declare_index_insert(const struct lu_env *env, struct mdd_object *obj, umode_t mode, struct thandle *th) { - struct dt_insert_rec *rec = &mdd_env_info(env)->mti_dt_rec; - struct mdd_device *mdd = mdo2mdd(&obj->mod_obj); - struct dt_key *key; - int rc; + struct dt_insert_rec *rec = &mdd_env_info(env)->mti_dt_rec; + struct mdd_device *mdd = mdo2mdd(&obj->mod_obj); + struct dt_key *key; + int rc; - key = orph_key_fill(env, mdo2fid(obj), ORPH_OP_UNLINK); + key = orph_key_fill(env, mdo2fid(obj)); rec->rec_fid = mdo2fid(obj); rec->rec_type = mode; @@ -237,20 +234,18 @@ out: RETURN(rc); } -int orph_declare_index_delete(const struct lu_env *env, - struct mdd_object *obj, - - struct thandle *th) +int orph_declare_index_delete(const struct lu_env *env, struct mdd_object *obj, + struct thandle *th) { - struct mdd_device *mdd = mdo2mdd(&obj->mod_obj); - struct dt_key *key; - int rc; + struct mdd_device *mdd = mdo2mdd(&obj->mod_obj); + struct dt_key *key; + int rc; - key = orph_key_fill(env, mdo2fid(obj), ORPH_OP_UNLINK); + key = orph_key_fill(env, mdo2fid(obj)); rc = dt_declare_delete(env, mdd->mdd_orphans, key, th); - if (rc) - return rc; + if (rc) + return rc; rc = mdo_declare_ref_del(env, obj, th); if (rc) @@ -267,48 +262,47 @@ int orph_declare_index_delete(const struct lu_env *env, return rc; } -static int orph_index_delete(const struct lu_env *env, - struct mdd_object *obj, - __u32 op, - struct thandle *th) +static int orph_index_delete(const struct lu_env *env, struct mdd_object *obj, + __u32 op, struct thandle *th) { - struct mdd_device *mdd = mdo2mdd(&obj->mod_obj); - struct dt_object *dor = mdd->mdd_orphans; - struct dt_key *key; - int rc; + struct mdd_device *mdd = mdo2mdd(&obj->mod_obj); + struct dt_object *dor = mdd->mdd_orphans; + struct dt_key *key; + int rc; - ENTRY; + ENTRY; - LASSERT(mdd_write_locked(env, obj) != 0); - LASSERT(obj->mod_flags & ORPHAN_OBJ); - LASSERT(obj->mod_count == 0); + LASSERT(mdd_write_locked(env, obj) != 0); + LASSERT(obj->mod_flags & ORPHAN_OBJ); + LASSERT(obj->mod_count == 0); - LASSERT(dor); + LASSERT(dor); - key = orph_key_fill(env, mdo2fid(obj), op); - mdd_orphan_write_lock(env, mdd); + key = orph_key_fill(env, mdo2fid(obj), op); + mdd_orphan_write_lock(env, mdd); - rc = mdd_orphan_delete_obj(env, mdd, key, th); + rc = mdd_orphan_delete_obj(env, mdd, key, th); - if (rc == -ENOENT) { - key = orph_key_fill_18(env, mdo2fid(obj)); - rc = mdd_orphan_delete_obj(env, mdd, key, th); - } + if (rc == -ENOENT) { + key = orph_key_fill_20(env, mdo2fid(obj)); + rc = mdd_orphan_delete_obj(env, mdd, key, th); + } - if (!rc) { - /* lov objects will be destroyed by caller */ - mdo_ref_del(env, obj, th); - if (S_ISDIR(mdd_object_type(obj))) { - mdo_ref_del(env, obj, th); - mdd_orphan_ref_del(env, mdd, th); - } - obj->mod_flags &= ~ORPHAN_OBJ; - } else { - CERROR("could not delete object: rc = %d\n",rc); - } + if (!rc) { + /* lov objects will be destroyed by caller */ + mdo_ref_del(env, obj, th); + if (S_ISDIR(mdd_object_type(obj))) { + mdo_ref_del(env, obj, th); + mdd_orphan_ref_del(env, mdd, th); + } + obj->mod_flags &= ~ORPHAN_OBJ; + } else { + CERROR("%s: could not delete orphan object "DFID": rc = %d\n", + mdd2obd_dev(mdd)->obd_name, PFID(mdo2fid(obj)), rc); + } - mdd_orphan_write_unlock(env, mdd); - RETURN(rc); + mdd_orphan_write_unlock(env, mdd); + RETURN(rc); } @@ -618,10 +612,10 @@ out: * \retval 0 success * \retval -ve index operation error. */ -int __mdd_orphan_add(const struct lu_env *env, - struct mdd_object *obj, struct thandle *th) +int __mdd_orphan_add(const struct lu_env *env, struct mdd_object *obj, + struct thandle *th) { - return orph_index_insert(env, obj, ORPH_OP_UNLINK, th); + return orph_index_insert(env, obj, th); } /** @@ -634,8 +628,8 @@ int __mdd_orphan_add(const struct lu_env *env, * \retval 0 success * \retval -ve index operation error. */ -int __mdd_orphan_del(const struct lu_env *env, - struct mdd_object *obj, struct thandle *th) +int __mdd_orphan_del(const struct lu_env *env, struct mdd_object *obj, + struct thandle *th) { - return orph_index_delete(env, obj, ORPH_OP_UNLINK, th); + return orph_index_delete(env, obj, th); } -- 1.8.3.1