Whamcloud - gitweb
LU-744 clio: save memory allocations for cl_page
[fs/lustre-release.git] / lustre / lov / lovsub_object.c
index 39f4edd..536039d 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) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -42,7 +42,9 @@
 
 #include "lov_cl_internal.h"
 
-/** \addtogroup lov lov @{ */
+/** \addtogroup lov
+ *  @{
+ */
 
 /*****************************************************************************
  *
@@ -64,6 +66,7 @@ int lovsub_object_init(const struct lu_env *env, struct lu_object *obj,
         below = under->ld_ops->ldo_object_alloc(env, obj->lo_header, under);
         if (below != NULL) {
                 lu_object_add(obj, below);
+               cl_object_page_init(lu2cl(obj), sizeof(struct lovsub_page));
                 result = 0;
         } else
                 result = -ENOMEM;
@@ -75,12 +78,19 @@ static void lovsub_object_free(const struct lu_env *env, struct lu_object *obj)
 {
         struct lovsub_object *los = lu2lovsub(obj);
         struct lov_object    *lov = los->lso_super;
+        ENTRY;
 
-        LASSERT(lov->lo_type == LLT_RAID0);
-        LASSERT(lov->u.raid0.lo_sub[los->lso_index] == los);
+        /* We can't assume lov was assigned here, because of the shadow
+         * object handling in lu_object_find.
+         */
+        if (lov) {
+                LASSERT(lov->lo_type == LLT_RAID0);
+                LASSERT(lov->u.raid0.lo_sub[los->lso_index] == los);
+               spin_lock(&lov->u.raid0.lo_sub_lock);
+               lov->u.raid0.lo_sub[los->lso_index] = NULL;
+               spin_unlock(&lov->u.raid0.lo_sub_lock);
+        }
 
-        ENTRY;
-        lov->u.raid0.lo_sub[los->lso_index] = NULL;
         lu_object_fini(obj);
         lu_object_header_fini(&los->lso_header.coh_lu);
         OBD_SLAB_FREE_PTR(los, lovsub_object_kmem);
@@ -92,7 +102,7 @@ static int lovsub_object_print(const struct lu_env *env, void *cookie,
 {
         struct lovsub_object *los = lu2lovsub(obj);
 
-        return (*p)(env, cookie, "[%i]", los->lso_index);
+        return (*p)(env, cookie, "[%d]", los->lso_index);
 }
 
 static int lovsub_attr_set(const struct lu_env *env, struct cl_object *obj,
@@ -134,7 +144,7 @@ static const struct lu_object_operations lovsub_lu_obj_ops = {
 };
 
 struct lu_object *lovsub_object_alloc(const struct lu_env *env,
-                                      const struct lu_object_header *_,
+                                      const struct lu_object_header *unused,
                                       struct lu_device *dev)
 {
         struct lovsub_object *los;