Whamcloud - gitweb
LU-2469 test: Skip failing ZFS tests
[fs/lustre-release.git] / lustre / mdd / mdd_orphans.c
index ab164a2..e364903 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -29,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, Whamcloud, Inc.
+ * Copyright (c) 2011, 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -43,9 +41,6 @@
  *         Pravin B Shelar <pravin.shelar@sun.com>
  */
 
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
 #define DEBUG_SUBSYSTEM S_MDS
 
 #include <obd.h>
@@ -69,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);
@@ -85,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);
@@ -97,29 +92,6 @@ static struct dt_key* orph_key_fill_18(const struct lu_env *env,
                 return ERR_PTR(rc);
 }
 
-static int orphan_key_to_fid(char *key, struct lu_fid *lf)
-{
-        int rc = 0;
-        unsigned int op;
-
-        rc = sscanf(key, ORPHAN_FILE_NAME_FORMAT,
-                    (long long unsigned int *)&lf->f_seq, &lf->f_oid,
-                    &lf->f_ver, &op);
-        if (rc == 4)
-                return 0;
-
-        /* build igif */
-        rc = sscanf(key, ORPHAN_FILE_NAME_FORMAT_18,
-                    (long long unsigned int *)&lf->f_seq, &lf->f_oid);
-        if (rc == 2) {
-                lf->f_ver = 0;
-                return 0;
-        }
-
-        CERROR("can not parse orphan file name %s\n", key);
-        return -EINVAL;
-}
-
 static inline void mdd_orphan_write_lock(const struct lu_env *env,
                                     struct mdd_device *mdd)
 {
@@ -183,38 +155,41 @@ 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,
-                              struct thandle *th)
+                             struct mdd_object *obj,
+                             cfs_umode_t mode, struct thandle *th)
 {
-        struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
-        int                rc;
+       struct mdd_device       *mdd = mdo2mdd(&obj->mod_obj);
+       struct dt_key           *key;
+       int                     rc;
 
-        rc = dt_declare_insert(env, mdd->mdd_orphans, NULL, NULL, th);
-        if (rc)
-                return rc;
+       key = orph_key_fill(env, mdo2fid(obj), ORPH_OP_UNLINK);
 
-        rc = mdo_declare_ref_add(env, obj, th);
-        if (rc)
-                return rc;
+       rc = dt_declare_insert(env, mdd->mdd_orphans, NULL, key, th);
+       if (rc)
+               return rc;
 
-        if (!S_ISDIR(mdd_object_type(obj)))
-                return 0;
+       rc = mdo_declare_ref_add(env, obj, th);
+       if (rc)
+               return rc;
 
-        rc = mdo_declare_ref_add(env, obj, th);
-        if (rc)
-                return rc;
+       if (!S_ISDIR(mode))
+               return 0;
 
-        rc = dt_declare_ref_add(env, mdd->mdd_orphans, th);
-        if (rc)
-                return rc;
+       rc = mdo_declare_ref_add(env, obj, th);
+       if (rc)
+               return rc;
 
-        rc = mdo_declare_index_delete(env, obj, dotdot, th);
-        if (rc)
-                return rc;
+       rc = dt_declare_ref_add(env, mdd->mdd_orphans, th);
+       if (rc)
+               return rc;
 
-        rc = mdo_declare_index_insert(env, obj, NULL, dotdot, th);
+       rc = mdo_declare_index_delete(env, obj, dotdot, th);
+       if (rc)
+               return rc;
 
-        return rc;
+       rc = mdo_declare_index_insert(env, obj, NULL, dotdot, th);
+
+       return rc;
 }
 
 static int orph_index_insert(const struct lu_env *env,
@@ -231,7 +206,6 @@ static int orph_index_insert(const struct lu_env *env,
 
         LASSERT(mdd_write_locked(env, obj) != 0);
         LASSERT(!(obj->mod_flags & ORPHAN_OBJ));
-        LASSERT(obj->mod_count > 0);
 
         mdd_orphan_write_lock(env, mdd);
 
@@ -268,50 +242,18 @@ out:
         RETURN(rc);
 }
 
-/**
- * Destroy OSD object on MDD and associated OST objects.
- *
- * \param obj orphan object
- * \param mdd used for sending llog msg to osts
- *
- * \retval  0   success
- * \retval -ve  error
- */
-static int orphan_object_kill(const struct lu_env *env,
-                              struct mdd_object *obj,
-                              struct mdd_device *mdd,
-                              struct thandle *th)
-{
-        struct lu_attr *la = &mdd_env_info(env)->mti_la;
-        int rc = 0;
-        ENTRY;
-
-        /* No need to lock this object as its recovery phase, and
-         * no other thread can access it. But we need to lock it
-         * as its precondition for osd api we using. */
-
-        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);
-        } else {
-                /* regular file , cleanup linked ost objects */
-                rc = mdd_la_get(env, obj, la, BYPASS_CAPA);
-                if (rc == 0)
-                        rc = mdd_lov_destroy(env, mdd, obj, la);
-        }
-        mdo_destroy(env, obj, th);
-        RETURN(rc);
-}
-
 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;
 
-        rc = dt_declare_delete(env, mdd->mdd_orphans, NULL, th);
+       key = orph_key_fill(env, mdo2fid(obj), ORPH_OP_UNLINK);
+
+       rc = dt_declare_delete(env, mdd->mdd_orphans, key, th);
         if (rc)
                 return rc;
 
@@ -381,18 +323,9 @@ static int orphan_object_destroy(const struct lu_env *env,
 {
         struct thandle *th = NULL;
         struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
-        struct md_attr *ma = &mdd_env_info(env)->mti_ma;
         int rc = 0;
         ENTRY;
 
-        /* init ma */
-        ma->ma_lmm_size = mdd_lov_mdsize(env, mdd);
-        ma->ma_lmm = mdd_max_lmm_get(env, mdd);
-        ma->ma_cookie_size = mdd_lov_cookiesize(env, mdd);
-        ma->ma_cookie = mdd_max_cookie_get(env, mdd);
-        ma->ma_need = MA_INODE | MA_LOV | MA_COOKIE;
-        ma->ma_valid = 0;
-
         th = mdd_trans_create(env, mdd);
         if (IS_ERR(th)) {
                 CERROR("Cannot get thandle\n");
@@ -402,7 +335,7 @@ static int orphan_object_destroy(const struct lu_env *env,
         if (rc)
                 GOTO(stop, rc);
 
-        rc = mdd_declare_object_kill(env, obj, ma, th);
+       rc = mdo_declare_destroy(env, obj, th);
         if (rc)
                 GOTO(stop, rc);
 
@@ -414,9 +347,14 @@ static int orphan_object_destroy(const struct lu_env *env,
         if (likely(obj->mod_count == 0)) {
                 mdd_orphan_write_lock(env, mdd);
                 rc = mdd_orphan_delete_obj(env, mdd, key, th);
-                if (rc == 0)
-                        orphan_object_kill(env, obj, mdd, th);
-                else
+               if (rc == 0) {
+                       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);
+                       }
+                       rc = mdo_destroy(env, obj, th);
+               } else
                         CERROR("could not delete object: rc = %d\n",rc);
                 mdd_orphan_write_unlock(env, mdd);
         }
@@ -458,7 +396,7 @@ static int orph_key_test_and_del(const struct lu_env *env,
                 if (rc) /* so replay-single.sh test_37 works */
                         CERROR("%s: error unlinking orphan "DFID" from "
                                "PENDING: rc = %d\n",
-                               mdd->mdd_obd_dev->obd_name, PFID(lf), rc);
+                              mdd2obd_dev(mdd)->obd_name, PFID(lf), rc);
         } else {
                 mdd_write_lock(env, mdo, MOR_TGT_CHILD);
                 if (likely(mdo->mod_count > 0)) {
@@ -486,15 +424,13 @@ static int orph_key_test_and_del(const struct lu_env *env,
  * \retval -ve error
  */
 static int orph_index_iterate(const struct lu_env *env,
-                              struct mdd_device *mdd)
+                             struct mdd_device *mdd)
 {
-        struct dt_object *dor = mdd->mdd_orphans;
-        char             *mti_key = mdd_env_info(env)->mti_orph_key;
-        const struct dt_it_ops *iops;
-        struct dt_it     *it;
-        char             *key;
-        struct lu_fid     fid;
-        int               result = 0;
+       struct dt_object *dor = mdd->mdd_orphans;
+       struct lu_dirent *ent = &mdd_env_info(env)->mti_ent;
+       const struct dt_it_ops *iops;
+       struct dt_it     *it;
+       struct lu_fid     fid;
         int               key_sz = 0;
         int               rc;
         __u64             cookie;
@@ -506,7 +442,7 @@ static int orph_index_iterate(const struct lu_env *env,
         if (IS_ERR(it)) {
                 rc = PTR_ERR(it);
                 CERROR("%s: cannot clean PENDING: rc = %d\n",
-                       mdd->mdd_obd_dev->obd_name, rc);
+                      mdd2obd_dev(mdd)->obd_name, rc);
                 GOTO(out, rc);
         }
 
@@ -515,57 +451,53 @@ static int orph_index_iterate(const struct lu_env *env,
                 GOTO(out_put, rc);
         if (rc == 0) {
                 CERROR("%s: error loading iterator to clean PENDING\n",
-                       mdd->mdd_obd_dev->obd_name);
+                      mdd2obd_dev(mdd)->obd_name);
                 /* Index contains no zero key? */
                 GOTO(out_put, rc = -EIO);
         }
 
-        do {
-                key = (void *)iops->key(env, it);
-                if (IS_ERR(key)) {
-                        CERROR("%s: key failed when clean PENDING: rc = %ld\n",
-                               mdd->mdd_obd_dev->obd_name, PTR_ERR(key));
-                        goto next;
-                }
-                key_sz = iops->key_size(env, it);
-
-                /* filter out "." and ".." entries from PENDING dir. */
-                if (key_sz < 8)
-                        goto next;
-
-                memcpy(mti_key, key, key_sz);
-                mti_key[key_sz] = 0;
-
-                if (orphan_key_to_fid(mti_key, &fid))
-                        goto next;
-                if (!fid_is_sane(&fid)) {
-                        CERROR("%s: bad FID "DFID" cleaning PENDING\n",
-                               mdd->mdd_obd_dev->obd_name, PFID(&fid));
-                        goto next;
-                }
-
-                /* kill orphan object */
-                cookie = iops->store(env, it);
-                iops->put(env, it);
-                rc = orph_key_test_and_del(env, mdd, &fid,
-                                          (struct dt_key *)mti_key);
-
-                /* after index delete reset iterator */
-                if (rc == 0)
-                        result = iops->get(env, it, (const void *)"");
-                else
-                        result = iops->load(env, it, cookie);
+       do {
+               key_sz = iops->key_size(env, it);
+               /* filter out "." and ".." entries from PENDING dir. */
+               if (key_sz < 8)
+                       goto next;
+
+               rc = iops->rec(env, it, (struct dt_rec *)ent, LUDA_64BITHASH);
+               if (rc != 0) {
+                       CERROR("%s: fail to get FID for orphan it: rc = %d\n",
+                              mdd2obd_dev(mdd)->obd_name, rc);
+                       goto next;
+               }
+
+               fid_le_to_cpu(&fid, &ent->lde_fid);
+               if (!fid_is_sane(&fid)) {
+                       CERROR("%s: bad FID "DFID" cleaning PENDING\n",
+                              mdd2obd_dev(mdd)->obd_name, PFID(&fid));
+                       goto next;
+               }
+
+               /* kill orphan object */
+               cookie = iops->store(env, it);
+               iops->put(env, it);
+               rc = orph_key_test_and_del(env, mdd, &fid,
+                                          (struct dt_key *)ent->lde_name);
+
+               /* after index delete reset iterator */
+               if (rc == 0)
+                       rc = iops->get(env, it, (const void *)"");
+               else
+                       rc = iops->load(env, it, cookie);
 next:
-                result = iops->next(env, it);
-        } while (result == 0);
+               rc = iops->next(env, it);
+       } while (rc == 0);
 
-        GOTO(out_put, rc = 0);
+       GOTO(out_put, rc = 0);
 out_put:
-        iops->put(env, it);
-        iops->fini(env, it);
+       iops->put(env, it);
+       iops->fini(env, it);
 
 out:
-        return rc;
+       return rc;
 }
 
 /**