4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * Implementation of cl_object for LOVSUB layer.
34 * Author: Nikita Danilov <nikita.danilov@sun.com>
37 #define DEBUG_SUBSYSTEM S_LOV
39 #include "lov_cl_internal.h"
45 /*****************************************************************************
47 * Lovsub object operations.
51 int lovsub_object_init(const struct lu_env *env, struct lu_object *obj,
52 const struct lu_object_conf *conf)
54 struct lovsub_device *dev = lu2lovsub_dev(obj->lo_dev);
55 struct lu_object *below;
56 struct lu_device *under;
61 under = &dev->acid_next->cd_lu_dev;
62 below = under->ld_ops->ldo_object_alloc(env, obj->lo_header, under);
64 lu_object_add(obj, below);
65 cl_object_page_init(lu2cl(obj), 0);
73 static void lovsub_object_free(const struct lu_env *env, struct lu_object *obj)
75 struct lovsub_object *los = lu2lovsub(obj);
76 struct lov_object *lov = los->lso_super;
81 * We can't assume lov was assigned here, because of the shadow
82 * object handling in lu_object_find.
85 int index = lov_comp_entry(los->lso_index);
86 int stripe = lov_comp_stripe(los->lso_index);
87 struct lov_layout_raid0 *r0 = lov_r0(lov, index);
89 LASSERT(lov->lo_type == LLT_COMP);
90 LASSERT(r0->lo_sub[stripe] == los);
91 spin_lock(&r0->lo_sub_lock);
92 r0->lo_sub[stripe] = NULL;
93 spin_unlock(&r0->lo_sub_lock);
97 lu_object_header_fini(&los->lso_header.coh_lu);
98 OBD_SLAB_FREE_PTR(los, lovsub_object_kmem);
102 static int lovsub_object_print(const struct lu_env *env, void *cookie,
103 lu_printer_t p, const struct lu_object *obj)
105 struct lovsub_object *los = lu2lovsub(obj);
107 return (*p)(env, cookie, "[%d]", los->lso_index);
110 static int lovsub_attr_update(const struct lu_env *env, struct cl_object *obj,
111 const struct cl_attr *attr, unsigned valid)
113 struct lovsub_object *los = cl2lovsub(obj);
114 struct lov_object *lov = cl2lovsub(obj)->lso_super;
117 lov_r0(lov, lov_comp_entry(los->lso_index))->lo_attr_valid = 0;
121 static int lovsub_object_glimpse(const struct lu_env *env,
122 const struct cl_object *obj,
125 struct lovsub_object *los = cl2lovsub(obj);
128 RETURN(cl_object_glimpse(env, &los->lso_super->lo_cl, lvb));
132 * Implementation of struct cl_object_operations::coo_req_attr_set() for lovsub
133 * layer. Lov and lovsub are responsible only for struct obdo::o_stripe_idx
134 * field, which is filled there.
136 static void lovsub_req_attr_set(const struct lu_env *env, struct cl_object *obj,
137 struct cl_req_attr *attr)
139 struct lovsub_object *subobj = cl2lovsub(obj);
140 struct lov_stripe_md *lsm = subobj->lso_super->lo_lsm;
143 cl_req_attr_set(env, &subobj->lso_super->lo_cl, attr);
146 * There is no OBD_MD_* flag for obdo::o_stripe_idx, so set it
147 * unconditionally. It never changes anyway.
149 attr->cra_oa->o_stripe_idx = lov_comp_stripe(subobj->lso_index);
150 lov_lsm2layout(lsm, lsm->lsm_entries[lov_comp_entry(subobj->lso_index)],
151 &attr->cra_oa->o_layout);
152 attr->cra_oa->o_valid |= OBD_MD_FLOSTLAYOUT;
156 static const struct cl_object_operations lovsub_ops = {
157 .coo_attr_update = lovsub_attr_update,
158 .coo_glimpse = lovsub_object_glimpse,
159 .coo_req_attr_set = lovsub_req_attr_set
162 static const struct lu_object_operations lovsub_lu_obj_ops = {
163 .loo_object_init = lovsub_object_init,
164 .loo_object_delete = NULL,
165 .loo_object_release = NULL,
166 .loo_object_free = lovsub_object_free,
167 .loo_object_print = lovsub_object_print,
168 .loo_object_invariant = NULL
171 struct lu_object *lovsub_object_alloc(const struct lu_env *env,
172 const struct lu_object_header *unused,
173 struct lu_device *dev)
175 struct lovsub_object *los;
176 struct lu_object *obj;
179 OBD_SLAB_ALLOC_PTR_GFP(los, lovsub_object_kmem, GFP_NOFS);
181 struct cl_object_header *hdr;
183 obj = lovsub2lu(los);
184 hdr = &los->lso_header;
185 cl_object_header_init(hdr);
186 lu_object_init(obj, &hdr->coh_lu, dev);
187 lu_object_add_top(&hdr->coh_lu, obj);
188 los->lso_cl.co_ops = &lovsub_ops;
189 obj->lo_ops = &lovsub_lu_obj_ops;