Whamcloud - gitweb
LU-427 test: Test failure on test suite lfsck
[fs/lustre-release.git] / lustre / lmv / lmv_object.c
index b96f9f9..60631c8 100644 (file)
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  */
 /*
+ * Copyright (c) 2011 Whamcloud, Inc.
+ */
+/*
  * This file is part of Lustre, http://www.lustre.org/
  * Lustre is a trademark of Sun Microsystems, Inc.
  */
@@ -50,8 +53,8 @@
 #include <liblustre.h>
 #endif
 
-#include <lustre/lustre_idl.h>
 #include <obd_support.h>
+#include <lustre/lustre_idl.h>
 #include <lustre_lib.h>
 #include <lustre_net.h>
 #include <lustre_dlm.h>
 #include "lmv_internal.h"
 
 extern cfs_mem_cache_t *lmv_object_cache;
-extern atomic_t lmv_object_count;
+extern cfs_atomic_t lmv_object_count;
 
 static CFS_LIST_HEAD(obj_list);
-static spinlock_t obj_list_lock = SPIN_LOCK_UNLOCKED;
+static cfs_spinlock_t obj_list_lock = CFS_SPIN_LOCK_UNLOCKED;
 
 struct lmv_object *lmv_object_alloc(struct obd_device *obd,
                                     const struct lu_fid *fid,
@@ -82,26 +85,24 @@ struct lmv_object *lmv_object_alloc(struct obd_device *obd,
         if (!obj)
                 return NULL;
 
-        atomic_inc(&lmv_object_count);
+        cfs_atomic_inc(&lmv_object_count);
 
         obj->lo_fid = *fid;
         obj->lo_obd = obd;
         obj->lo_state = 0;
         obj->lo_hashtype = mea->mea_magic;
 
-        init_MUTEX(&obj->lo_guard);
-        atomic_set(&obj->lo_count, 0);
+        cfs_init_mutex(&obj->lo_guard);
+        cfs_atomic_set(&obj->lo_count, 0);
         obj->lo_objcount = mea->mea_count;
 
         obj_size = sizeof(struct lmv_stripe) * 
                 lmv->desc.ld_tgt_count;
 
-        OBD_ALLOC(obj->lo_stripes, obj_size);
+        OBD_ALLOC_LARGE(obj->lo_stripes, obj_size);
         if (!obj->lo_stripes)
                 goto err_obj;
 
-        memset(obj->lo_stripes, 0, obj_size);
-
         CDEBUG(D_INODE, "Allocate object for "DFID"\n", 
                PFID(fid));
         for (i = 0; i < mea->mea_count; i++) {
@@ -133,54 +134,54 @@ void lmv_object_free(struct lmv_object *obj)
         struct lmv_obd          *lmv = &obj->lo_obd->u.lmv;
         unsigned int             obj_size;
 
-        LASSERT(!atomic_read(&obj->lo_count));
+        LASSERT(!cfs_atomic_read(&obj->lo_count));
 
         obj_size = sizeof(struct lmv_stripe) *
                 lmv->desc.ld_tgt_count;
 
-        OBD_FREE(obj->lo_stripes, obj_size);
+        OBD_FREE_LARGE(obj->lo_stripes, obj_size);
         OBD_SLAB_FREE(obj, lmv_object_cache, sizeof(*obj));
-        atomic_dec(&lmv_object_count);
+        cfs_atomic_dec(&lmv_object_count);
 }
 
 static void __lmv_object_add(struct lmv_object *obj)
 {
-        atomic_inc(&obj->lo_count);
-        list_add(&obj->lo_list, &obj_list);
+        cfs_atomic_inc(&obj->lo_count);
+        cfs_list_add(&obj->lo_list, &obj_list);
 }
 
 void lmv_object_add(struct lmv_object *obj)
 {
-        spin_lock(&obj_list_lock);
+        cfs_spin_lock(&obj_list_lock);
         __lmv_object_add(obj);
-        spin_unlock(&obj_list_lock);
+        cfs_spin_unlock(&obj_list_lock);
 }
 
 static void __lmv_object_del(struct lmv_object *obj)
 {
-        list_del(&obj->lo_list);
+        cfs_list_del(&obj->lo_list);
         lmv_object_free(obj);
 }
 
 void lmv_object_del(struct lmv_object *obj)
 {
-        spin_lock(&obj_list_lock);
+        cfs_spin_lock(&obj_list_lock);
         __lmv_object_del(obj);
-        spin_unlock(&obj_list_lock);
+        cfs_spin_unlock(&obj_list_lock);
 }
 
 static struct lmv_object *__lmv_object_get(struct lmv_object *obj)
 {
         LASSERT(obj != NULL);
-        atomic_inc(&obj->lo_count);
+        cfs_atomic_inc(&obj->lo_count);
         return obj;
 }
 
 struct lmv_object *lmv_object_get(struct lmv_object *obj)
 {
-        spin_lock(&obj_list_lock);
+        cfs_spin_lock(&obj_list_lock);
         __lmv_object_get(obj);
-        spin_unlock(&obj_list_lock);
+        cfs_spin_unlock(&obj_list_lock);
         return obj;
 }
 
@@ -188,7 +189,7 @@ static void __lmv_object_put(struct lmv_object *obj)
 {
         LASSERT(obj);
 
-        if (atomic_dec_and_test(&obj->lo_count)) {
+        if (cfs_atomic_dec_and_test(&obj->lo_count)) {
                 CDEBUG(D_INODE, "Last reference to "DFID" - "
                        "destroying\n", PFID(&obj->lo_fid));
                 __lmv_object_del(obj);
@@ -197,9 +198,9 @@ static void __lmv_object_put(struct lmv_object *obj)
 
 void lmv_object_put(struct lmv_object *obj)
 {
-        spin_lock(&obj_list_lock);
+        cfs_spin_lock(&obj_list_lock);
         __lmv_object_put(obj);
-        spin_unlock(&obj_list_lock);
+        cfs_spin_unlock(&obj_list_lock);
 }
 
 void lmv_object_put_unlock(struct lmv_object *obj)
@@ -211,14 +212,14 @@ void lmv_object_put_unlock(struct lmv_object *obj)
 static struct lmv_object *__lmv_object_find(struct obd_device *obd, const struct lu_fid *fid)
 {
         struct lmv_object       *obj;
-        struct list_head        *cur;
+        cfs_list_t              *cur;
 
-        list_for_each(cur, &obj_list) {
-                obj = list_entry(cur, struct lmv_object, lo_list);
+        cfs_list_for_each(cur, &obj_list) {
+                obj = cfs_list_entry(cur, struct lmv_object, lo_list);
 
-                /* 
+                /*
                  * Check if object is in destroying phase. If so - skip
-                 * it. 
+                 * it.
                  */
                 if (obj->lo_state & O_FREEING)
                         continue;
@@ -233,8 +234,8 @@ static struct lmv_object *__lmv_object_find(struct obd_device *obd, const struct
                 if (obj->lo_obd != obd)
                         continue;
 
-                /* 
-                 * Check if this is what we're looking for. 
+                /*
+                 * Check if this is what we're looking for.
                  */
                 if (lu_fid_eq(&obj->lo_fid, fid))
                         return __lmv_object_get(obj);
@@ -243,15 +244,19 @@ static struct lmv_object *__lmv_object_find(struct obd_device *obd, const struct
         return NULL;
 }
 
-struct lmv_object *lmv_object_find(struct obd_device *obd, 
+struct lmv_object *lmv_object_find(struct obd_device *obd,
                                    const struct lu_fid *fid)
 {
-        struct lmv_object       *obj;
+        struct lmv_obd          *lmv = &obd->u.lmv;
+        struct lmv_object       *obj = NULL;
         ENTRY;
 
-        spin_lock(&obj_list_lock);
-        obj = __lmv_object_find(obd, fid);
-        spin_unlock(&obj_list_lock);
+        /* For single MDT case, lmv_object list is always empty. */
+        if (lmv->desc.ld_tgt_count > 1) {
+                cfs_spin_lock(&obj_list_lock);
+                obj = __lmv_object_find(obd, fid);
+                cfs_spin_unlock(&obj_list_lock);
+        }
 
         RETURN(obj);
 }
@@ -289,13 +294,13 @@ static struct lmv_object *__lmv_object_create(struct obd_device *obd,
          * Check if someone created it already while we were dealing with
          * allocating @obj. 
          */
-        spin_lock(&obj_list_lock);
+        cfs_spin_lock(&obj_list_lock);
         obj = __lmv_object_find(obd, fid);
         if (obj) {
                 /* 
                  * Someone created it already - put @obj and getting out. 
                  */
-                spin_unlock(&obj_list_lock);
+                cfs_spin_unlock(&obj_list_lock);
                 lmv_object_free(new);
                 RETURN(obj);
         }
@@ -303,7 +308,7 @@ static struct lmv_object *__lmv_object_create(struct obd_device *obd,
         __lmv_object_add(new);
         __lmv_object_get(new);
 
-        spin_unlock(&obj_list_lock);
+        cfs_spin_unlock(&obj_list_lock);
 
         CDEBUG(D_INODE, "New obj in lmv cache: "DFID"\n",
                PFID(fid));
@@ -329,15 +334,16 @@ struct lmv_object *lmv_object_create(struct obd_export *exp,
                PFID(fid));
 
         md.mea = NULL;
-       
+
         if (mea == NULL) {
+                struct md_op_data *op_data;
                 __u64 valid;
 
                 CDEBUG(D_INODE, "Mea isn't passed in, get it now\n");
                 mealen = lmv_get_easize(lmv);
 
-                /* 
-                 * Time to update mea of parent fid. 
+                /*
+                 * Time to update mea of parent fid.
                  */
                 md.mea = NULL;
                 valid = OBD_MD_FLEASIZE | OBD_MD_FLDIREA | OBD_MD_MEA;
@@ -346,7 +352,15 @@ struct lmv_object *lmv_object_create(struct obd_export *exp,
                 if (IS_ERR(tgt))
                         GOTO(cleanup, obj = (void *)tgt);
 
-                rc = md_getattr(tgt->ltd_exp, fid, NULL, valid, mealen, &req);
+                OBD_ALLOC_PTR(op_data);
+                if (op_data == NULL)
+                        GOTO(cleanup, obj = ERR_PTR(-ENOMEM));
+
+                op_data->op_fid1 = *fid;
+                op_data->op_mode = mealen;
+                op_data->op_valid = valid;
+                rc = md_getattr(tgt->ltd_exp, op_data, &req);
+                OBD_FREE_PTR(op_data);
                 if (rc) {
                         CERROR("md_getattr() failed, error %d\n", rc);
                         GOTO(cleanup, obj = ERR_PTR(rc));
@@ -364,8 +378,8 @@ struct lmv_object *lmv_object_create(struct obd_export *exp,
                 mea = md.mea;
         }
 
-        /* 
-         * Got mea, now create obj for it. 
+        /*
+         * Got mea, now create obj for it.
          */
         obj = __lmv_object_create(obd, fid, mea);
         if (!obj) {
@@ -391,7 +405,7 @@ int lmv_object_delete(struct obd_export *exp, const struct lu_fid *fid)
         int                      rc = 0;
         ENTRY;
 
-        spin_lock(&obj_list_lock);
+        cfs_spin_lock(&obj_list_lock);
         obj = __lmv_object_find(obd, fid);
         if (obj) {
                 obj->lo_state |= O_FREEING;
@@ -399,7 +413,7 @@ int lmv_object_delete(struct obd_export *exp, const struct lu_fid *fid)
                 __lmv_object_put(obj);
                 rc = 1;
         }
-        spin_unlock(&obj_list_lock);
+        cfs_spin_unlock(&obj_list_lock);
         RETURN(rc);
 }
 
@@ -416,28 +430,29 @@ int lmv_object_setup(struct obd_device *obd)
 
 void lmv_object_cleanup(struct obd_device *obd)
 {
-        struct list_head        *cur;
-        struct list_head        *tmp;
+        cfs_list_t              *cur;
+        cfs_list_t              *tmp;
         struct lmv_object       *obj;
         ENTRY;
 
         CDEBUG(D_INFO, "LMV object manager cleanup (%s)\n",
                obd->obd_uuid.uuid);
 
-        spin_lock(&obj_list_lock);
-        list_for_each_safe(cur, tmp, &obj_list) {
-                obj = list_entry(cur, struct lmv_object, lo_list);
+        cfs_spin_lock(&obj_list_lock);
+        cfs_list_for_each_safe(cur, tmp, &obj_list) {
+                obj = cfs_list_entry(cur, struct lmv_object, lo_list);
 
                 if (obj->lo_obd != obd)
                         continue;
 
                 obj->lo_state |= O_FREEING;
-                if (atomic_read(&obj->lo_count) > 1) {
+                if (cfs_atomic_read(&obj->lo_count) > 1) {
                         CERROR("Object "DFID" has count (%d)\n", 
-                               PFID(&obj->lo_fid), atomic_read(&obj->lo_count));
+                               PFID(&obj->lo_fid),
+                               cfs_atomic_read(&obj->lo_count));
                 }
                 __lmv_object_put(obj);
         }
-        spin_unlock(&obj_list_lock);
+        cfs_spin_unlock(&obj_list_lock);
         EXIT;
 }