Whamcloud - gitweb
LU-14487 modules: remove references to Sun Trademark.
[fs/lustre-release.git] / lustre / lov / lovsub_object.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  *
31  * Implementation of cl_object for LOVSUB layer.
32  *
33  *   Author: Nikita Danilov <nikita.danilov@sun.com>
34  */
35
36 #define DEBUG_SUBSYSTEM S_LOV
37
38 #include "lov_cl_internal.h"
39
40 /** \addtogroup lov
41  *  @{
42  */
43
44 /*****************************************************************************
45  *
46  * Lovsub object operations.
47  *
48  */
49
50 static int lovsub_object_init(const struct lu_env *env, struct lu_object *obj,
51                               const struct lu_object_conf *conf)
52 {
53         struct lovsub_device *dev = lu2lovsub_dev(obj->lo_dev);
54         struct lu_object *below;
55         struct lu_device *under;
56         int result;
57
58         ENTRY;
59         under = &dev->acid_next->cd_lu_dev;
60         below = under->ld_ops->ldo_object_alloc(env, obj->lo_header, under);
61         if (below) {
62                 lu_object_add(obj, below);
63                 cl_object_page_init(lu2cl(obj), 0);
64                 result = 0;
65         } else
66                 result = -ENOMEM;
67         RETURN(result);
68
69 }
70
71 static void lovsub_object_free_rcu(struct rcu_head *head)
72 {
73         struct lovsub_object *los = container_of(head, struct lovsub_object,
74                                                  lso_header.coh_lu.loh_rcu);
75
76         kmem_cache_free(lovsub_object_kmem, los);
77 }
78
79 static void lovsub_object_free(const struct lu_env *env, struct lu_object *obj)
80 {
81         struct lovsub_object *los = lu2lovsub(obj);
82         struct lov_object *lov = los->lso_super;
83
84         ENTRY;
85
86         /*
87          * We can't assume lov was assigned here, because of the shadow
88          * object handling in lu_object_find.
89          */
90         if (lov) {
91                 int index = lov_comp_entry(los->lso_index);
92                 int stripe = lov_comp_stripe(los->lso_index);
93                 struct lov_layout_raid0 *r0 = lov_r0(lov, index);
94
95                 LASSERT(lov->lo_type == LLT_COMP);
96                 LASSERT(r0->lo_sub[stripe] == los);
97                 spin_lock(&r0->lo_sub_lock);
98                 r0->lo_sub[stripe] = NULL;
99                 spin_unlock(&r0->lo_sub_lock);
100         }
101
102         lu_object_fini(obj);
103         lu_object_header_fini(&los->lso_header.coh_lu);
104         OBD_FREE_PRE(los, sizeof(*los), "slab-freed");
105         call_rcu(&los->lso_header.coh_lu.loh_rcu, lovsub_object_free_rcu);
106         EXIT;
107 }
108
109 static int lovsub_object_print(const struct lu_env *env, void *cookie,
110                                lu_printer_t p, const struct lu_object *obj)
111 {
112         struct lovsub_object *los = lu2lovsub(obj);
113
114         return (*p)(env, cookie, "[%d]", los->lso_index);
115 }
116
117 static int lovsub_attr_update(const struct lu_env *env, struct cl_object *obj,
118                               const struct cl_attr *attr, unsigned valid)
119 {
120         struct lovsub_object *los = cl2lovsub(obj);
121         struct lov_object *lov = cl2lovsub(obj)->lso_super;
122
123         ENTRY;
124         lov_r0(lov, lov_comp_entry(los->lso_index))->lo_attr_valid = 0;
125         RETURN(0);
126 }
127
128 static int lovsub_object_glimpse(const struct lu_env *env,
129                                  const struct cl_object *obj,
130                                  struct ost_lvb *lvb)
131 {
132         struct lovsub_object *los = cl2lovsub(obj);
133
134         ENTRY;
135         RETURN(cl_object_glimpse(env, &los->lso_super->lo_cl, lvb));
136 }
137
138 /**
139  * Implementation of struct cl_object_operations::coo_req_attr_set() for lovsub
140  * layer. Lov and lovsub are responsible only for struct obdo::o_stripe_idx
141  * field, which is filled there.
142  */
143 static void lovsub_req_attr_set(const struct lu_env *env, struct cl_object *obj,
144                                 struct cl_req_attr *attr)
145 {
146         struct lovsub_object *subobj = cl2lovsub(obj);
147         struct lov_stripe_md *lsm = subobj->lso_super->lo_lsm;
148
149         ENTRY;
150         cl_req_attr_set(env, &subobj->lso_super->lo_cl, attr);
151
152         /*
153          * There is no OBD_MD_* flag for obdo::o_stripe_idx, so set it
154          * unconditionally. It never changes anyway.
155          */
156         attr->cra_oa->o_stripe_idx = lov_comp_stripe(subobj->lso_index);
157         lov_lsm2layout(lsm, lsm->lsm_entries[lov_comp_entry(subobj->lso_index)],
158                        &attr->cra_oa->o_layout);
159         attr->cra_oa->o_valid |= OBD_MD_FLOSTLAYOUT;
160         EXIT;
161 }
162
163 static const struct cl_object_operations lovsub_ops = {
164         .coo_attr_update  = lovsub_attr_update,
165         .coo_glimpse      = lovsub_object_glimpse,
166         .coo_req_attr_set = lovsub_req_attr_set
167 };
168
169 static const struct lu_object_operations lovsub_lu_obj_ops = {
170         .loo_object_init      = lovsub_object_init,
171         .loo_object_delete    = NULL,
172         .loo_object_release   = NULL,
173         .loo_object_free      = lovsub_object_free,
174         .loo_object_print     = lovsub_object_print,
175         .loo_object_invariant = NULL
176 };
177
178 struct lu_object *lovsub_object_alloc(const struct lu_env *env,
179                                       const struct lu_object_header *unused,
180                                       struct lu_device *dev)
181 {
182         struct lovsub_object *los;
183         struct lu_object     *obj;
184
185         ENTRY;
186         OBD_SLAB_ALLOC_PTR_GFP(los, lovsub_object_kmem, GFP_NOFS);
187         if (los) {
188                 struct cl_object_header *hdr;
189
190                 obj = lovsub2lu(los);
191                 hdr = &los->lso_header;
192                 cl_object_header_init(hdr);
193                 lu_object_init(obj, &hdr->coh_lu, dev);
194                 lu_object_add_top(&hdr->coh_lu, obj);
195                 los->lso_cl.co_ops = &lovsub_ops;
196                 obj->lo_ops = &lovsub_lu_obj_ops;
197         } else
198                 obj = NULL;
199         RETURN(obj);
200 }
201
202 /** @} lov */