Whamcloud - gitweb
LU-7734 lnet: set primary NID in ptlrpc_connection_get()
[fs/lustre-release.git] / lustre / lov / lovsub_object.c
index 3774df9..752a422 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.
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * 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, 2015, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -66,6 +62,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;
@@ -85,7 +82,9 @@ static void lovsub_object_free(const struct lu_env *env, struct lu_object *obj)
         if (lov) {
                 LASSERT(lov->lo_type == LLT_RAID0);
                 LASSERT(lov->u.raid0.lo_sub[los->lso_index] == los);
-                lov->u.raid0.lo_sub[los->lso_index] = NULL;
+               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);
         }
 
         lu_object_fini(obj);
@@ -99,17 +98,17 @@ 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,
-                           const struct cl_attr *attr, unsigned valid)
+static int lovsub_attr_update(const struct lu_env *env, struct cl_object *obj,
+                             const struct cl_attr *attr, unsigned valid)
 {
-        struct lov_object *lov = cl2lovsub(obj)->lso_super;
+       struct lov_object *lov = cl2lovsub(obj)->lso_super;
 
-        ENTRY;
-        lov_r0(lov)->lo_attr_valid = 0;
-        RETURN(0);
+       ENTRY;
+       lov_r0(lov)->lo_attr_valid = 0;
+       RETURN(0);
 }
 
 static int lovsub_object_glimpse(const struct lu_env *env,
@@ -122,13 +121,33 @@ static int lovsub_object_glimpse(const struct lu_env *env,
         RETURN(cl_object_glimpse(env, &los->lso_super->lo_cl, lvb));
 }
 
+/**
+ * Implementation of struct cl_object_operations::coo_req_attr_set() for lovsub
+ * layer. Lov and lovsub are responsible only for struct obdo::o_stripe_idx
+ * field, which is filled there.
+ */
+static void lovsub_req_attr_set(const struct lu_env *env, struct cl_object *obj,
+                               struct cl_req_attr *attr)
+{
+       struct lovsub_object *subobj = cl2lovsub(obj);
+
+       ENTRY;
+       cl_req_attr_set(env, &subobj->lso_super->lo_cl, attr);
 
+       /*
+        * There is no OBD_MD_* flag for obdo::o_stripe_idx, so set it
+        * unconditionally. It never changes anyway.
+        */
+       attr->cra_oa->o_stripe_idx = subobj->lso_index;
+       EXIT;
+}
 
 static const struct cl_object_operations lovsub_ops = {
-        .coo_page_init = lovsub_page_init,
-        .coo_lock_init = lovsub_lock_init,
-        .coo_attr_set  = lovsub_attr_set,
-        .coo_glimpse   = lovsub_object_glimpse
+       .coo_page_init    = lovsub_page_init,
+       .coo_lock_init    = lovsub_lock_init,
+       .coo_attr_update  = lovsub_attr_update,
+       .coo_glimpse      = lovsub_object_glimpse,
+       .coo_req_attr_set = lovsub_req_attr_set
 };
 
 static const struct lu_object_operations lovsub_lu_obj_ops = {
@@ -141,27 +160,27 @@ 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 *unused,
-                                      struct lu_device *dev)
+                                     const struct lu_object_header *unused,
+                                     struct lu_device *dev)
 {
-        struct lovsub_object *los;
-        struct lu_object     *obj;
-
-        ENTRY;
-        OBD_SLAB_ALLOC_PTR_GFP(los, lovsub_object_kmem, CFS_ALLOC_IO);
-        if (los != NULL) {
-                struct cl_object_header *hdr;
-
-                obj = lovsub2lu(los);
-                hdr = &los->lso_header;
-                cl_object_header_init(hdr);
-                lu_object_init(obj, &hdr->coh_lu, dev);
-                lu_object_add_top(&hdr->coh_lu, obj);
-                los->lso_cl.co_ops = &lovsub_ops;
-                obj->lo_ops = &lovsub_lu_obj_ops;
-        } else
-                obj = NULL;
-        RETURN(obj);
+       struct lovsub_object *los;
+       struct lu_object     *obj;
+
+       ENTRY;
+       OBD_SLAB_ALLOC_PTR_GFP(los, lovsub_object_kmem, GFP_NOFS);
+       if (los != NULL) {
+               struct cl_object_header *hdr;
+
+               obj = lovsub2lu(los);
+               hdr = &los->lso_header;
+               cl_object_header_init(hdr);
+               lu_object_init(obj, &hdr->coh_lu, dev);
+               lu_object_add_top(&hdr->coh_lu, obj);
+               los->lso_cl.co_ops = &lovsub_ops;
+               obj->lo_ops = &lovsub_lu_obj_ops;
+       } else
+               obj = NULL;
+       RETURN(obj);
 }
 
 /** @} lov */