Whamcloud - gitweb
OBD_SLAB_ALLOC_PTR_SAFE() is a new OBD_ macro for slab allocation that uses CFS_ALLOC...
[fs/lustre-release.git] / lustre / lov / lovsub_object.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * Implementation of cl_object for LOVSUB layer.
37  *
38  *   Author: Nikita Danilov <nikita.danilov@sun.com>
39  */
40
41 #define DEBUG_SUBSYSTEM S_LOV
42
43 #include "lov_cl_internal.h"
44
45 /** \addtogroup lov lov @{ */
46
47 /*****************************************************************************
48  *
49  * Lovsub object operations.
50  *
51  */
52
53 int lovsub_object_init(const struct lu_env *env, struct lu_object *obj,
54                        const struct lu_object_conf *conf)
55 {
56         struct lovsub_device  *dev   = lu2lovsub_dev(obj->lo_dev);
57         struct lu_object      *below;
58         struct lu_device      *under;
59
60         int result;
61
62         ENTRY;
63         under = &dev->acid_next->cd_lu_dev;
64         below = under->ld_ops->ldo_object_alloc(env, obj->lo_header, under);
65         if (below != NULL) {
66                 lu_object_add(obj, below);
67                 result = 0;
68         } else
69                 result = -ENOMEM;
70         RETURN(result);
71
72 }
73
74 static void lovsub_object_free(const struct lu_env *env, struct lu_object *obj)
75 {
76         struct lovsub_object *los = lu2lovsub(obj);
77         struct lov_object    *lov = los->lso_super;
78
79         LASSERT(lov->lo_type == LLT_RAID0);
80         LASSERT(lov->u.raid0.lo_sub[los->lso_index] == los);
81
82         ENTRY;
83         lov->u.raid0.lo_sub[los->lso_index] = NULL;
84         lu_object_fini(obj);
85         lu_object_header_fini(&los->lso_header.coh_lu);
86         OBD_SLAB_FREE_PTR(los, lovsub_object_kmem);
87         EXIT;
88 }
89
90 static int lovsub_object_print(const struct lu_env *env, void *cookie,
91                                lu_printer_t p, const struct lu_object *obj)
92 {
93         struct lovsub_object *los = lu2lovsub(obj);
94
95         return (*p)(env, cookie, "[%i]", los->lso_index);
96 }
97
98 static int lovsub_attr_set(const struct lu_env *env, struct cl_object *obj,
99                            const struct cl_attr *attr, unsigned valid)
100 {
101         struct lov_object *lov = cl2lovsub(obj)->lso_super;
102
103         ENTRY;
104         lov_r0(lov)->lo_attr_valid = 0;
105         RETURN(0);
106 }
107
108 static int lovsub_object_glimpse(const struct lu_env *env,
109                                  const struct cl_object *obj,
110                                  struct ost_lvb *lvb)
111 {
112         struct lovsub_object *los = cl2lovsub(obj);
113
114         ENTRY;
115         RETURN(cl_object_glimpse(env, &los->lso_super->lo_cl, lvb));
116 }
117
118
119
120 static const struct cl_object_operations lovsub_ops = {
121         .coo_page_init = lovsub_page_init,
122         .coo_lock_init = lovsub_lock_init,
123         .coo_attr_set  = lovsub_attr_set,
124         .coo_glimpse   = lovsub_object_glimpse
125 };
126
127 static const struct lu_object_operations lovsub_lu_obj_ops = {
128         .loo_object_init      = lovsub_object_init,
129         .loo_object_delete    = NULL,
130         .loo_object_release   = NULL,
131         .loo_object_free      = lovsub_object_free,
132         .loo_object_print     = lovsub_object_print,
133         .loo_object_invariant = NULL
134 };
135
136 struct lu_object *lovsub_object_alloc(const struct lu_env *env,
137                                       const struct lu_object_header *_,
138                                       struct lu_device *dev)
139 {
140         struct lovsub_object *los;
141         struct lu_object     *obj;
142
143         ENTRY;
144         OBD_SLAB_ALLOC_PTR_GFP(los, lovsub_object_kmem, CFS_ALLOC_IO);
145         if (los != NULL) {
146                 struct cl_object_header *hdr;
147
148                 obj = lovsub2lu(los);
149                 hdr = &los->lso_header;
150                 cl_object_header_init(hdr);
151                 lu_object_init(obj, &hdr->coh_lu, dev);
152                 lu_object_add_top(&hdr->coh_lu, obj);
153                 los->lso_cl.co_ops = &lovsub_ops;
154                 obj->lo_ops = &lovsub_lu_obj_ops;
155         } else
156                 obj = NULL;
157         RETURN(obj);
158 }
159
160 /** @} lov */