1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
5 * Use is subject to license terms.
7 * Copyright (c) 2012, 2017, Intel Corporation.
11 * This file is part of Lustre, http://www.lustre.org/
13 * Implementation of cl_object for LOVSUB layer.
15 * Author: Nikita Danilov <nikita.danilov@sun.com>
18 #define DEBUG_SUBSYSTEM S_LOV
20 #include "lov_cl_internal.h"
27 * Lovsub object operations.
30 static int lovsub_object_init(const struct lu_env *env, struct lu_object *obj,
31 const struct lu_object_conf *conf)
33 struct lovsub_device *dev = lu2lovsub_dev(obj->lo_dev);
34 struct lu_object *below;
35 struct lu_device *under;
39 under = &dev->acid_next->cd_lu_dev;
40 below = under->ld_ops->ldo_object_alloc(env, obj->lo_header, under);
42 lu_object_add(obj, below);
43 cl_object_page_init(lu2cl(obj), 0);
51 static void lovsub_object_free_rcu(struct rcu_head *head)
53 struct lovsub_object *los = container_of(head, struct lovsub_object,
54 lso_header.coh_lu.loh_rcu);
56 kmem_cache_free(lovsub_object_kmem, los);
59 static void lovsub_object_free(const struct lu_env *env, struct lu_object *obj)
61 struct lovsub_object *los = lu2lovsub(obj);
62 struct lov_object *lov = los->lso_super;
67 * We can't assume lov was assigned here, because of the shadow
68 * object handling in lu_object_find.
71 int index = lov_comp_entry(los->lso_index);
72 int stripe = lov_comp_stripe(los->lso_index);
73 struct lov_layout_raid0 *r0 = lov_r0(lov, index);
75 LASSERT(lov->lo_type == LLT_COMP);
76 LASSERT(r0->lo_sub[stripe] == los);
77 spin_lock(&r0->lo_sub_lock);
78 r0->lo_sub[stripe] = NULL;
79 spin_unlock(&r0->lo_sub_lock);
83 lu_object_header_fini(&los->lso_header.coh_lu);
84 OBD_FREE_PRE(los, sizeof(*los), "slab-freed");
85 call_rcu(&los->lso_header.coh_lu.loh_rcu, lovsub_object_free_rcu);
89 static int lovsub_object_print(const struct lu_env *env, void *cookie,
90 lu_printer_t p, const struct lu_object *obj)
92 struct lovsub_object *los = lu2lovsub(obj);
94 return (*p)(env, cookie, "[%d]", los->lso_index);
97 static int lovsub_attr_update(const struct lu_env *env, struct cl_object *obj,
98 const struct cl_attr *attr,
99 enum cl_attr_valid valid)
101 struct lovsub_object *los = cl2lovsub(obj);
102 struct lov_object *lov = cl2lovsub(obj)->lso_super;
105 lov_r0(lov, lov_comp_entry(los->lso_index))->lo_attr_valid = 0;
109 static int lovsub_object_glimpse(const struct lu_env *env,
110 const struct cl_object *obj,
113 struct lovsub_object *los = cl2lovsub(obj);
116 RETURN(cl_object_glimpse(env, &los->lso_super->lo_cl, lvb));
120 * Implementation of struct cl_object_operations::coo_req_attr_set() for lovsub
121 * layer. Lov and lovsub are responsible only for struct obdo::o_stripe_idx
122 * field, which is filled there.
124 static void lovsub_req_attr_set(const struct lu_env *env, struct cl_object *obj,
125 struct cl_req_attr *attr)
127 struct lovsub_object *subobj = cl2lovsub(obj);
128 struct lov_stripe_md *lsm = subobj->lso_super->lo_lsm;
131 cl_req_attr_set(env, &subobj->lso_super->lo_cl, attr);
134 * There is no OBD_MD_* flag for obdo::o_stripe_idx, so set it
135 * unconditionally. It never changes anyway.
137 attr->cra_oa->o_stripe_idx = lov_comp_stripe(subobj->lso_index);
138 lov_lsm2layout(lsm, lsm->lsm_entries[lov_comp_entry(subobj->lso_index)],
139 &attr->cra_oa->o_layout);
140 attr->cra_oa->o_valid |= OBD_MD_FLOSTLAYOUT;
144 static void lovsub_req_projid_set(const struct lu_env *env,
145 struct cl_object *obj, __u32 *projid)
147 struct lovsub_object *subobj = cl2lovsub(obj);
150 cl_req_projid_set(env, &subobj->lso_super->lo_cl, projid);
154 static const struct cl_object_operations lovsub_ops = {
155 .coo_attr_update = lovsub_attr_update,
156 .coo_glimpse = lovsub_object_glimpse,
157 .coo_req_attr_set = lovsub_req_attr_set,
158 .coo_req_projid_set = lovsub_req_projid_set,
161 static const struct lu_object_operations lovsub_lu_obj_ops = {
162 .loo_object_init = lovsub_object_init,
163 .loo_object_delete = NULL,
164 .loo_object_release = NULL,
165 .loo_object_free = lovsub_object_free,
166 .loo_object_print = lovsub_object_print,
167 .loo_object_invariant = NULL
170 struct lu_object *lovsub_object_alloc(const struct lu_env *env,
171 const struct lu_object_header *unused,
172 struct lu_device *dev)
174 struct lovsub_object *los;
175 struct lu_object *obj;
178 OBD_SLAB_ALLOC_PTR_GFP(los, lovsub_object_kmem, GFP_NOFS);
180 struct cl_object_header *hdr;
182 obj = lovsub2lu(los);
183 hdr = &los->lso_header;
184 cl_object_header_init(hdr);
185 lu_object_init(obj, &hdr->coh_lu, dev);
186 lu_object_add_top(&hdr->coh_lu, obj);
187 los->lso_cl.co_ops = &lovsub_ops;
188 obj->lo_ops = &lovsub_lu_obj_ops;