Whamcloud - gitweb
LU-10030 hsm: make changelog flag argument an enum
[fs/lustre-release.git] / lustre / mdd / mdd_object.c
index 2d28256..c04c685 100644 (file)
@@ -55,7 +55,7 @@ static const struct lu_object_operations mdd_lu_obj_ops;
 
 struct mdd_object_user {
        struct list_head        mou_list;       /**< linked off mod_users */
-       int                     mou_flags;      /**< open mode by client */
+       u64                     mou_open_flags; /**< open mode by client */
        __u64                   mou_uidgid;     /**< uid_gid on client */
        int                     mou_opencount;  /**< # opened */
        ktime_t                 mou_deniednext; /**< time of next access denied
@@ -70,28 +70,29 @@ static int mdd_xattr_get(const struct lu_env *env,
 static int mdd_changelog_data_store_by_fid(const struct lu_env *env,
                                           struct mdd_device *mdd,
                                           enum changelog_rec_type type,
-                                          int flags, const struct lu_fid *fid,
+                                          enum changelog_rec_flags clf_flags,
+                                          const struct lu_fid *fid,
                                           const char *xattr_name,
                                           struct thandle *handle);
 
 static inline bool has_prefix(const char *str, const char *prefix);
 
 
-static unsigned int flags_helper(int flags)
+static u32 flags_helper(u64 open_flags)
 {
-       unsigned int mflags = 0;
+       u32 open_mode = 0;
 
-       if (flags & MDS_FMODE_EXEC) {
-               mflags = MDS_FMODE_EXEC;
+       if (open_flags & MDS_FMODE_EXEC) {
+               open_mode = MDS_FMODE_EXEC;
        } else {
-               if (flags & MDS_FMODE_READ)
-                       mflags = MDS_FMODE_READ;
-               if (flags &
+               if (open_flags & MDS_FMODE_READ)
+                       open_mode = MDS_FMODE_READ;
+               if (open_flags &
                    (MDS_FMODE_WRITE | MDS_OPEN_TRUNC | MDS_OPEN_APPEND))
-                       mflags |= MDS_FMODE_WRITE;
+                       open_mode |= MDS_FMODE_WRITE;
        }
 
-       return mflags;
+       return open_mode;
 }
 
 /** Allocate/init a user and its sub-structures.
@@ -102,7 +103,7 @@ static unsigned int flags_helper(int flags)
  * \retval mou [OUT] success valid structure
  * \retval mou [OUT]
  */
-static struct mdd_object_user *mdd_obj_user_alloc(int flags,
+static struct mdd_object_user *mdd_obj_user_alloc(u64 open_flags,
                                                  uid_t uid, gid_t gid)
 {
        struct mdd_object_user *mou;
@@ -113,7 +114,7 @@ static struct mdd_object_user *mdd_obj_user_alloc(int flags,
        if (mou == NULL)
                RETURN(ERR_PTR(-ENOMEM));
 
-       mou->mou_flags = flags;
+       mou->mou_open_flags = open_flags;
        mou->mou_uidgid = ((__u64)uid << 32) | gid;
        mou->mou_opencount = 0;
        mou->mou_deniednext = ktime_set(0, 0);
@@ -142,7 +143,8 @@ static void mdd_obj_user_free(struct mdd_object_user *mou)
  */
 static
 struct mdd_object_user *mdd_obj_user_find(struct mdd_object *mdd_obj,
-                                         uid_t uid, gid_t gid, int flags)
+                                         uid_t uid, gid_t gid,
+                                         u64 open_flags)
 {
        struct mdd_object_user *mou;
        __u64 uidgid;
@@ -152,7 +154,8 @@ struct mdd_object_user *mdd_obj_user_find(struct mdd_object *mdd_obj,
        uidgid = ((__u64)uid << 32) | gid;
        list_for_each_entry(mou, &mdd_obj->mod_users, mou_list) {
                if (mou->mou_uidgid == uidgid &&
-                   flags_helper(mou->mou_flags) == flags_helper(flags))
+                   flags_helper(mou->mou_open_flags) ==
+                   flags_helper(open_flags))
                        RETURN(mou);
        }
        RETURN(NULL);
@@ -177,9 +180,7 @@ static int mdd_obj_user_add(struct mdd_object *mdd_obj,
        __u32 gid = mou->mou_uidgid & ((1UL << 32) - 1);
 
        ENTRY;
-
-       tmp = mdd_obj_user_find(mdd_obj, uid,
-                               gid, mou->mou_flags);
+       tmp = mdd_obj_user_find(mdd_obj, uid, gid, mou->mou_open_flags);
        if (tmp != NULL)
                RETURN(-EEXIST);
 
@@ -843,22 +844,23 @@ static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj,
 static int mdd_changelog_data_store_by_fid(const struct lu_env *env,
                                           struct mdd_device *mdd,
                                           enum changelog_rec_type type,
-                                          int flags, const struct lu_fid *fid,
+                                          enum changelog_rec_flags clf_flags,
+                                          const struct lu_fid *fid,
                                           const char *xattr_name,
                                           struct thandle *handle)
 {
        const struct lu_ucred *uc = lu_ucred(env);
+       enum changelog_rec_extra_flags xflags = CLFE_INVALID;
        struct llog_changelog_rec *rec;
        struct lu_buf *buf;
        int reclen;
-       int xflags = CLFE_INVALID;
        int rc;
 
-       flags = (flags & CLF_FLAGMASK) | CLF_VERSION | CLF_EXTRA_FLAGS;
+       clf_flags = (clf_flags & CLF_FLAGMASK) | CLF_VERSION | CLF_EXTRA_FLAGS;
 
        if (uc) {
                if (uc->uc_jobid[0] != '\0')
-                       flags |= CLF_JOBID;
+                       clf_flags |= CLF_JOBID;
                xflags |= CLFE_UIDGID;
                xflags |= CLFE_NID;
        }
@@ -868,7 +870,7 @@ static int mdd_changelog_data_store_by_fid(const struct lu_env *env,
                xflags |= CLFE_XATTR;
 
        reclen = llog_data_len(LLOG_CHANGELOG_HDR_SZ +
-                              changelog_rec_offset(flags & CLF_SUPPORTED,
+                              changelog_rec_offset(clf_flags & CLF_SUPPORTED,
                                                    xflags & CLFE_SUPPORTED));
        buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_big_buf, reclen);
        if (buf->lb_buf == NULL)
@@ -876,15 +878,15 @@ static int mdd_changelog_data_store_by_fid(const struct lu_env *env,
        rec = buf->lb_buf;
 
        rec->cr_hdr.lrh_len = reclen;
-       rec->cr.cr_flags = flags;
+       rec->cr.cr_flags = clf_flags;
        rec->cr.cr_type = (__u32)type;
        rec->cr.cr_tfid = *fid;
        rec->cr.cr_namelen = 0;
 
-       if (flags & CLF_JOBID)
+       if (clf_flags & CLF_JOBID)
                mdd_changelog_rec_ext_jobid(&rec->cr, uc->uc_jobid);
 
-       if (flags & CLF_EXTRA_FLAGS) {
+       if (clf_flags & CLF_EXTRA_FLAGS) {
                mdd_changelog_rec_ext_extra_flags(&rec->cr, xflags);
                if (xflags & CLFE_UIDGID)
                        mdd_changelog_rec_extra_uidgid(&rec->cr,
@@ -892,7 +894,7 @@ static int mdd_changelog_data_store_by_fid(const struct lu_env *env,
                if (xflags & CLFE_NID)
                        mdd_changelog_rec_extra_nid(&rec->cr, uc->uc_nid);
                if (xflags & CLFE_OPEN)
-                       mdd_changelog_rec_extra_omode(&rec->cr, flags);
+                       mdd_changelog_rec_extra_omode(&rec->cr, clf_flags);
                if (xflags & CLFE_XATTR) {
                        if (xattr_name == NULL)
                                RETURN(-EINVAL);
@@ -912,7 +914,8 @@ static int mdd_changelog_data_store_by_fid(const struct lu_env *env,
  * \param handle - transaction handle
  */
 int mdd_changelog_data_store(const struct lu_env *env, struct mdd_device *mdd,
-                            enum changelog_rec_type type, int flags,
+                            enum changelog_rec_type type,
+                            enum changelog_rec_flags clf_flags,
                             struct mdd_object *mdd_obj, struct thandle *handle)
 {
        int                              rc;
@@ -934,7 +937,7 @@ int mdd_changelog_data_store(const struct lu_env *env, struct mdd_device *mdd,
                RETURN(0);
        }
 
-       rc = mdd_changelog_data_store_by_fid(env, mdd, type, flags,
+       rc = mdd_changelog_data_store_by_fid(env, mdd, type, clf_flags,
                                             mdo2fid(mdd_obj), NULL, handle);
        if (rc == 0)
                mdd_obj->mod_cltime = ktime_get();
@@ -945,11 +948,12 @@ int mdd_changelog_data_store(const struct lu_env *env, struct mdd_device *mdd,
 int mdd_changelog_data_store_xattr(const struct lu_env *env,
                                   struct mdd_device *mdd,
                                   enum changelog_rec_type type,
-                                  int flags, struct mdd_object *mdd_obj,
+                                  enum changelog_rec_flags clf_flags,
+                                  struct mdd_object *mdd_obj,
                                   const char *xattr_name,
                                   struct thandle *handle)
 {
-       int                              rc;
+       int rc;
 
        LASSERT(mdd_obj != NULL);
        LASSERT(handle != NULL);
@@ -969,7 +973,7 @@ int mdd_changelog_data_store_xattr(const struct lu_env *env,
                RETURN(0);
        }
 
-       rc = mdd_changelog_data_store_by_fid(env, mdd, type, flags,
+       rc = mdd_changelog_data_store_by_fid(env, mdd, type, clf_flags,
                                             mdo2fid(mdd_obj), xattr_name,
                                             handle);
        if (rc == 0)
@@ -978,8 +982,11 @@ int mdd_changelog_data_store_xattr(const struct lu_env *env,
        RETURN(rc);
 }
 
+/* only the bottom CLF_FLAGSHIFT bits of @flags are stored in the record,
+ * except for open flags have a dedicated record to store 32 bits of flags */
 static int mdd_changelog(const struct lu_env *env, enum changelog_rec_type type,
-                 int flags, struct md_device *m, const struct lu_fid *fid)
+                        enum changelog_rec_flags clf_flags,
+                        struct md_device *m, const struct lu_fid *fid)
 {
        struct thandle *handle;
        struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
@@ -1005,7 +1012,7 @@ static int mdd_changelog(const struct lu_env *env, enum changelog_rec_type type,
        if (rc)
                GOTO(stop, rc);
 
-       rc = mdd_changelog_data_store_by_fid(env, mdd, type, flags,
+       rc = mdd_changelog_data_store_by_fid(env, mdd, type, clf_flags,
                                             fid, NULL, handle);
 
 stop:
@@ -1046,8 +1053,8 @@ static int mdd_attr_set_changelog(const struct lu_env *env,
        /* The record type is the lowest non-masked set bit */
        type = __ffs(bits);
 
-       /* FYI we only store the first CLF_FLAGMASK bits of la_valid */
-       return mdd_changelog_data_store(env, mdd, type, (int)valid,
+       /* XXX: we only store the low CLF_FLAGMASK bits of la_valid */
+       return mdd_changelog_data_store(env, mdd, type, valid,
                                        md2mdd_obj(obj), handle);
 }
 
@@ -1325,6 +1332,10 @@ mdd_xattr_changelog_type(const struct lu_env *env, struct mdd_device *mdd,
        if (strcmp(XATTR_NAME_HSM, xattr_name) == 0)
                return CL_HSM;
 
+       /* Avoid logging SOM xattr for every file */
+       if (strcmp(XATTR_NAME_SOM, xattr_name) == 0)
+               return CL_NONE;
+
        if (has_prefix(xattr_name, XATTR_USER_PREFIX) ||
            has_prefix(xattr_name, XATTR_NAME_POSIX_ACL_ACCESS) ||
            has_prefix(xattr_name, XATTR_NAME_POSIX_ACL_DEFAULT) ||
@@ -1332,7 +1343,7 @@ mdd_xattr_changelog_type(const struct lu_env *env, struct mdd_device *mdd,
            has_prefix(xattr_name, XATTR_SECURITY_PREFIX))
                return CL_SETXATTR;
 
-       return -1;
+       return CL_NONE;
 }
 
 static int mdd_declare_xattr_set(const struct lu_env *env,
@@ -1368,16 +1379,17 @@ static int mdd_declare_xattr_set(const struct lu_env *env,
 static int mdd_hsm_update_locked(const struct lu_env *env,
                                 struct md_object *obj,
                                 const struct lu_buf *buf,
-                                struct thandle *handle, int *cl_flags)
+                                struct thandle *handle,
+                                enum changelog_rec_flags *clf_flags)
 {
        struct mdd_thread_info *info = mdd_env_info(env);
-       struct mdd_object      *mdd_obj = md2mdd_obj(obj);
-       struct lu_buf          *current_buf;
-       struct md_hsm          *current_mh;
-       struct md_hsm          *new_mh;
-       int                     rc;
-       ENTRY;
+       struct mdd_object *mdd_obj = md2mdd_obj(obj);
+       struct lu_buf *current_buf;
+       struct md_hsm *current_mh;
+       struct md_hsm *new_mh;
+       int rc;
 
+       ENTRY;
        OBD_ALLOC_PTR(current_mh);
        if (current_mh == NULL)
                RETURN(-ENOMEM);
@@ -1402,9 +1414,9 @@ static int mdd_hsm_update_locked(const struct lu_env *env,
 
        /* Flags differ, set flags for the changelog that will be added */
        if (current_mh->mh_flags != new_mh->mh_flags) {
-               hsm_set_cl_event(cl_flags, HE_STATE);
+               hsm_set_cl_event(clf_flags, HE_STATE);
                if (new_mh->mh_flags & HS_DIRTY)
-                       hsm_set_cl_flags(cl_flags, CLF_HSM_DIRTY);
+                       hsm_set_cl_flags(clf_flags, CLF_HSM_DIRTY);
        }
 
        OBD_FREE_PTR(new_mh);
@@ -1812,13 +1824,13 @@ static int mdd_xattr_set(const struct lu_env *env, struct md_object *obj,
                         const struct lu_buf *buf, const char *name,
                         int fl)
 {
-       struct mdd_object       *mdd_obj = md2mdd_obj(obj);
-       struct lu_attr          *attr = MDD_ENV_VAR(env, cattr);
-       struct mdd_device       *mdd = mdo2mdd(obj);
-       struct thandle          *handle;
+       struct mdd_object *mdd_obj = md2mdd_obj(obj);
+       struct lu_attr *attr = MDD_ENV_VAR(env, cattr);
+       struct mdd_device *mdd = mdo2mdd(obj);
+       struct thandle *handle;
        enum changelog_rec_type  cl_type;
-       int                      cl_flags = 0;
-       int                      rc;
+       enum changelog_rec_flags clf_flags = 0;
+       int rc;
        ENTRY;
 
        rc = mdd_la_get(env, mdd_obj, attr);
@@ -1891,7 +1903,7 @@ static int mdd_xattr_set(const struct lu_env *env, struct md_object *obj,
        mdd_write_lock(env, mdd_obj, MOR_TGT_CHILD);
 
        if (strcmp(XATTR_NAME_HSM, name) == 0) {
-               rc = mdd_hsm_update_locked(env, obj, buf, handle, &cl_flags);
+               rc = mdd_hsm_update_locked(env, obj, buf, handle, &clf_flags);
                if (rc) {
                        mdd_write_unlock(env, mdd_obj);
                        GOTO(stop, rc);
@@ -1907,7 +1919,7 @@ static int mdd_xattr_set(const struct lu_env *env, struct md_object *obj,
        if (cl_type < 0)
                GOTO(stop, rc = 0);
 
-       rc = mdd_changelog_data_store_xattr(env, mdd, cl_type, cl_flags,
+       rc = mdd_changelog_data_store_xattr(env, mdd, cl_type, clf_flags,
                                            mdd_obj, name, handle);
 
        EXIT;
@@ -2038,8 +2050,8 @@ static int mdd_xattr_hsm_replace(const struct lu_env *env,
                                 struct thandle *handle)
 {
        struct hsm_attrs *attrs;
-       __u32 hsm_flags;
-       int flags = 0;
+       enum hsm_states hsm_flags;
+       enum changelog_rec_flags clf_flags = 0;
        int rc;
        ENTRY;
 
@@ -2054,9 +2066,9 @@ static int mdd_xattr_hsm_replace(const struct lu_env *env,
                RETURN(0);
 
        /* Add a changelog record for release. */
-       hsm_set_cl_event(&flags, HE_RELEASE);
+       hsm_set_cl_event(&clf_flags, HE_RELEASE);
        rc = mdd_changelog_data_store(env, mdo2mdd(&o->mod_obj), CL_HSM,
-                                     flags, o, handle);
+                                     clf_flags, o, handle);
        RETURN(rc);
 }
 
@@ -2949,54 +2961,47 @@ void mdd_object_make_hint(const struct lu_env *env, struct mdd_object *parent,
        nc->do_ops->do_ah_init(env, hint, np, nc, attr->la_mode & S_IFMT);
 }
 
-/*
- * do NOT or the MAY_*'s, you'll get the weakest
- */
-int accmode(const struct lu_env *env, const struct lu_attr *la, int flags)
+static int accmode(const struct lu_env *env, const struct lu_attr *la,
+                  u64 open_flags)
 {
-       int res = 0;
-
        /* Sadly, NFSD reopens a file repeatedly during operation, so the
         * "acc_mode = 0" allowance for newly-created files isn't honoured.
         * NFSD uses the MDS_OPEN_OWNEROVERRIDE flag to say that a file
         * owner can write to a file even if it is marked readonly to hide
         * its brokenness. (bug 5781) */
-       if (flags & MDS_OPEN_OWNEROVERRIDE) {
+       if (open_flags & MDS_OPEN_OWNEROVERRIDE) {
                struct lu_ucred *uc = lu_ucred_check(env);
 
                if ((uc == NULL) || (la->la_uid == uc->uc_fsuid))
                        return 0;
        }
 
-       if (flags & MDS_FMODE_READ)
-               res |= MAY_READ;
-       if (flags & (MDS_FMODE_WRITE | MDS_OPEN_TRUNC | MDS_OPEN_APPEND))
-               res |= MAY_WRITE;
-       if (flags & MDS_FMODE_EXEC)
-               res = MAY_EXEC;
-       return res;
+       return mds_accmode(open_flags);
 }
 
 static int mdd_open_sanity_check(const struct lu_env *env,
-                               struct mdd_object *obj,
-                               const struct lu_attr *attr, int flag)
+                                struct mdd_object *obj,
+                                const struct lu_attr *attr, u64 open_flags)
 {
        int mode, rc;
        ENTRY;
 
-       /* EEXIST check */
-       if (mdd_is_dead_obj(obj))
+       /* EEXIST check, also opening of *open* orphans is allowed so we can
+        * open-by-handle unlinked files
+        */
+       if (mdd_is_dead_obj(obj) &&
+           likely(!(mdd_is_orphan_obj(obj) && obj->mod_count > 0)))
                RETURN(-ENOENT);
 
        if (S_ISLNK(attr->la_mode))
                RETURN(-ELOOP);
 
-       mode = accmode(env, attr, flag);
+       mode = accmode(env, attr, open_flags);
 
        if (S_ISDIR(attr->la_mode) && (mode & MAY_WRITE))
                RETURN(-EISDIR);
 
-       if (!(flag & MDS_OPEN_CREATED)) {
+       if (!(open_flags & MDS_OPEN_CREATED)) {
                rc = mdd_permission_internal(env, obj, attr, mode);
                if (rc)
                        RETURN(rc);
@@ -3004,13 +3009,14 @@ static int mdd_open_sanity_check(const struct lu_env *env,
 
        if (S_ISFIFO(attr->la_mode) || S_ISSOCK(attr->la_mode) ||
            S_ISBLK(attr->la_mode) || S_ISCHR(attr->la_mode))
-               flag &= ~MDS_OPEN_TRUNC;
+               open_flags &= ~MDS_OPEN_TRUNC;
 
        /* For writing append-only file must open it with append mode. */
        if (attr->la_flags & LUSTRE_APPEND_FL) {
-               if ((flag & MDS_FMODE_WRITE) && !(flag & MDS_OPEN_APPEND))
+               if ((open_flags & MDS_FMODE_WRITE) &&
+                   !(open_flags & MDS_OPEN_APPEND))
                        RETURN(-EPERM);
-               if (flag & MDS_OPEN_TRUNC)
+               if (open_flags & MDS_OPEN_TRUNC)
                        RETURN(-EPERM);
        }
 
@@ -3018,7 +3024,7 @@ static int mdd_open_sanity_check(const struct lu_env *env,
 }
 
 static int mdd_open(const struct lu_env *env, struct md_object *obj,
-                   int flags)
+                   u64 open_flags)
 {
        struct mdd_object *mdd_obj = md2mdd_obj(obj);
        struct md_device *md_dev = lu2md_dev(mdd2lu_dev(mdo2mdd(obj)));
@@ -3035,7 +3041,7 @@ static int mdd_open(const struct lu_env *env, struct md_object *obj,
        if (rc != 0)
                GOTO(out, rc);
 
-       rc = mdd_open_sanity_check(env, mdd_obj, attr, flags);
+       rc = mdd_open_sanity_check(env, mdd_obj, attr, open_flags);
        if ((rc == -EACCES) && (mdd->mdd_cl.mc_mask & (1 << CL_DN_OPEN)))
                type = CL_DN_OPEN;
        else if (rc != 0)
@@ -3048,13 +3054,13 @@ static int mdd_open(const struct lu_env *env, struct md_object *obj,
 
 find:
        /* look for existing opener in list under mdd_write_lock */
-       mou = mdd_obj_user_find(mdd_obj, uc->uc_uid, uc->uc_gid, flags);
+       mou = mdd_obj_user_find(mdd_obj, uc->uc_uid, uc->uc_gid, open_flags);
 
        if (!mou) {
                int rc2;
 
                /* add user to list */
-               mou = mdd_obj_user_alloc(flags, uc->uc_uid, uc->uc_gid);
+               mou = mdd_obj_user_alloc(open_flags, uc->uc_uid, uc->uc_gid);
                if (IS_ERR(mou)) {
                        if (rc == 0)
                                rc = PTR_ERR(mou);
@@ -3090,7 +3096,8 @@ find:
                }
        }
 
-       mdd_changelog(env, type, flags, md_dev, mdo2fid(mdd_obj));
+       /* FYI, only the bottom 32 bits of open_flags are recorded */
+       mdd_changelog(env, type, open_flags, md_dev, mdo2fid(mdd_obj));
 
        EXIT;
 out:
@@ -3114,7 +3121,7 @@ static int mdd_declare_close(const struct lu_env *env, struct mdd_object *obj,
  * No permission check is needed.
  */
 static int mdd_close(const struct lu_env *env, struct md_object *obj,
-                    struct md_attr *ma, int mode)
+                    struct md_attr *ma, u64 open_flags)
 {
        struct mdd_object *mdd_obj = md2mdd_obj(obj);
        struct mdd_device *mdd = mdo2mdd(obj);
@@ -3213,7 +3220,8 @@ cont:
                 * the user had the file open. So the corresponding close
                 * will not be logged.
                 */
-               mou = mdd_obj_user_find(mdd_obj, uc->uc_uid, uc->uc_gid, mode);
+               mou = mdd_obj_user_find(mdd_obj, uc->uc_uid, uc->uc_gid,
+                                       open_flags);
                if (mou) {
                        mou->mou_opencount--;
                        if (mou->mou_opencount == 0) {
@@ -3272,7 +3280,8 @@ out:
         * CL_OPEN. Plus Changelogs mask may not change often.
         */
        if (((!(mdd->mdd_cl.mc_mask & (1 << CL_OPEN)) &&
-             (mode & (MDS_FMODE_WRITE | MDS_OPEN_APPEND | MDS_OPEN_TRUNC))) ||
+             (open_flags & (MDS_FMODE_WRITE | MDS_OPEN_APPEND |
+                            MDS_OPEN_TRUNC))) ||
             ((mdd->mdd_cl.mc_mask & (1 << CL_OPEN)) && last_close_by_uid)) &&
            !(ma->ma_valid & MA_FLAGS && ma->ma_attr_flags & MDS_RECOV_OPEN)) {
                if (handle == NULL) {
@@ -3285,14 +3294,15 @@ out:
                        if (rc)
                                GOTO(stop, rc);
 
-                        rc = mdd_trans_start(env, mdo2mdd(obj), handle);
-                        if (rc)
-                                GOTO(stop, rc);
-                }
+                       rc = mdd_trans_start(env, mdo2mdd(obj), handle);
+                       if (rc)
+                               GOTO(stop, rc);
+               }
 
-                mdd_changelog_data_store(env, mdd, CL_CLOSE, mode,
-                                         mdd_obj, handle);
-        }
+               /* FYI, only the bottom 32 bits of open_flags are recorded */
+               mdd_changelog_data_store(env, mdd, CL_CLOSE, open_flags,
+                                        mdd_obj, handle);
+       }
 
 stop:
        if (handle != NULL && !IS_ERR(handle))