Whamcloud - gitweb
LU-928 fid: add comments describing different FIDs
[fs/lustre-release.git] / lustre / lmv / lmv_object.c
index 6b3d821..f54f7b3 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.
  * 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.
  */
 
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
 #define DEBUG_SUBSYSTEM S_LMV
 #ifdef __KERNEL__
 #include <linux/slab.h>
@@ -50,8 +47,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>
@@ -63,7 +60,7 @@ extern cfs_mem_cache_t *lmv_object_cache;
 extern cfs_atomic_t lmv_object_count;
 
 static CFS_LIST_HEAD(obj_list);
-static cfs_spinlock_t obj_list_lock = CFS_SPIN_LOCK_UNLOCKED;
+static DEFINE_SPINLOCK(obj_list_lock);
 
 struct lmv_object *lmv_object_alloc(struct obd_device *obd,
                                     const struct lu_fid *fid,
@@ -89,19 +86,17 @@ struct lmv_object *lmv_object_alloc(struct obd_device *obd,
         obj->lo_state = 0;
         obj->lo_hashtype = mea->mea_magic;
 
-        cfs_init_mutex(&obj->lo_guard);
+        cfs_mutex_init(&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++) {
@@ -138,7 +133,7 @@ void lmv_object_free(struct lmv_object *obj)
         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));
         cfs_atomic_dec(&lmv_object_count);
 }
@@ -243,15 +238,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;
 
-        cfs_spin_lock(&obj_list_lock);
-        obj = __lmv_object_find(obd, fid);
-        cfs_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);
 }