Whamcloud - gitweb
LU-3500 mdt: use __u64 for sp_cr_flags
[fs/lustre-release.git] / lustre / mdd / mdd_orphans.c
index 6a741a3..9aa132b 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Intel Corporation.
+ * Copyright (c) 2011, 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -64,7 +64,7 @@ enum {
 static struct dt_key* orph_key_fill(const struct lu_env *env,
                                     const struct lu_fid *lf, __u32 op)
 {
-        char *key = mdd_env_info(env)->mti_orph_key;
+       char *key = mdd_env_info(env)->mti_key;
         int rc;
 
         LASSERT(key);
@@ -80,7 +80,7 @@ static struct dt_key* orph_key_fill(const struct lu_env *env,
 static struct dt_key* orph_key_fill_18(const struct lu_env *env,
                                        const struct lu_fid *lf)
 {
-        char *key = mdd_env_info(env)->mti_orph_key;
+       char *key = mdd_env_info(env)->mti_key;
         int rc;
 
         LASSERT(key);
@@ -156,7 +156,7 @@ static inline void mdd_orphan_ref_del(const struct lu_env *env,
 
 int orph_declare_index_insert(const struct lu_env *env,
                              struct mdd_object *obj,
-                             cfs_umode_t mode, struct thandle *th)
+                             umode_t mode, struct thandle *th)
 {
        struct mdd_device       *mdd = mdo2mdd(&obj->mod_obj);
        struct dt_key           *key;
@@ -326,11 +326,12 @@ static int orphan_object_destroy(const struct lu_env *env,
         int rc = 0;
         ENTRY;
 
-        th = mdd_trans_create(env, mdd);
-        if (IS_ERR(th)) {
-                CERROR("Cannot get thandle\n");
-                RETURN(-ENOMEM);
-        }
+       th = mdd_trans_create(env, mdd);
+       if (IS_ERR(th)) {
+               CERROR("Cannot get thandle\n");
+               RETURN(PTR_ERR(th));
+       }
+
         rc = orph_declare_index_delete(env, obj, th);
         if (rc)
                 GOTO(stop, rc);
@@ -427,7 +428,7 @@ static int orph_index_iterate(const struct lu_env *env,
                              struct mdd_device *mdd)
 {
        struct dt_object *dor = mdd->mdd_orphans;
-       struct lu_dirent *ent = &mdd_env_info(env)->mti_orph_ent;
+       struct lu_dirent *ent = &mdd_env_info(env)->mti_ent;
        const struct dt_it_ops *iops;
        struct dt_it     *it;
        struct lu_fid     fid;
@@ -518,26 +519,32 @@ out:
  */
 int orph_index_init(const struct lu_env *env, struct mdd_device *mdd)
 {
-        struct lu_fid fid;
-        struct dt_object *d;
-        int rc = 0;
-        ENTRY;
-
-        d = dt_store_open(env, mdd->mdd_child, "", orph_index_name, &fid);
-        if (!IS_ERR(d)) {
-                mdd->mdd_orphans = d;
-                if (!dt_try_as_dir(env, d)) {
-                        rc = -ENOTDIR;
-                        CERROR("\"%s\" is not an index! : rc = %d\n",
-                                        orph_index_name, rc);
-                }
-        } else {
-                CERROR("cannot find \"%s\" obj %d\n",
-                       orph_index_name, (int)PTR_ERR(d));
-                rc = PTR_ERR(d);
-        }
-
-        RETURN(rc);
+       struct lu_fid            fid;
+       struct dt_object        *d;
+       int                      rc = 0;
+
+       ENTRY;
+
+       /* create PENDING dir */
+       fid_zero(&fid);
+       rc = mdd_local_file_create(env, mdd, &mdd->mdd_local_root_fid,
+                                  orph_index_name, S_IFDIR | S_IRUGO |
+                                  S_IWUSR | S_IXUGO, &fid);
+       if (rc < 0)
+               RETURN(rc);
+
+       d = dt_locate(env, mdd->mdd_child, &fid);
+       if (IS_ERR(d))
+               RETURN(PTR_ERR(d));
+       LASSERT(lu_object_exists(&d->do_lu));
+       if (!dt_try_as_dir(env, d)) {
+               CERROR("%s: \"%s\" is not an index: rc = %d\n",
+                      mdd2obd_dev(mdd)->obd_name, orph_index_name, rc);
+               lu_object_put(env, &d->do_lu);
+               RETURN(-ENOTDIR);
+       }
+       mdd->mdd_orphans = d;
+       RETURN(0);
 }
 
 void orph_index_fini(const struct lu_env *env, struct mdd_device *mdd)