Whamcloud - gitweb
LU-19098 hsm: don't print progname twice with lhsmtool
[fs/lustre-release.git] / lustre / lov / lovsub_object.c
1 // SPDX-License-Identifier: GPL-2.0
2
3 /*
4  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
5  * Use is subject to license terms.
6  *
7  * Copyright (c) 2012, 2017, Intel Corporation.
8  */
9
10 /*
11  * This file is part of Lustre, http://www.lustre.org/
12  *
13  * Implementation of cl_object for LOVSUB layer.
14  *
15  * Author: Nikita Danilov <nikita.danilov@sun.com>
16  */
17
18 #define DEBUG_SUBSYSTEM S_LOV
19
20 #include "lov_cl_internal.h"
21
22 /** \addtogroup lov
23  *  @{
24  */
25
26 /**
27  * Lovsub object operations.
28  */
29
30 static int lovsub_object_init(const struct lu_env *env, struct lu_object *obj,
31                               const struct lu_object_conf *conf)
32 {
33         struct lovsub_device *dev = lu2lovsub_dev(obj->lo_dev);
34         struct lu_object *below;
35         struct lu_device *under;
36         int result;
37
38         ENTRY;
39         under = &dev->acid_next->cd_lu_dev;
40         below = under->ld_ops->ldo_object_alloc(env, obj->lo_header, under);
41         if (below) {
42                 lu_object_add(obj, below);
43                 cl_object_page_init(lu2cl(obj), 0);
44                 result = 0;
45         } else
46                 result = -ENOMEM;
47         RETURN(result);
48
49 }
50
51 static void lovsub_object_free_rcu(struct rcu_head *head)
52 {
53         struct lovsub_object *los = container_of(head, struct lovsub_object,
54                                                  lso_header.coh_lu.loh_rcu);
55
56         kmem_cache_free(lovsub_object_kmem, los);
57 }
58
59 static void lovsub_object_free(const struct lu_env *env, struct lu_object *obj)
60 {
61         struct lovsub_object *los = lu2lovsub(obj);
62         struct lov_object *lov = los->lso_super;
63
64         ENTRY;
65
66         /*
67          * We can't assume lov was assigned here, because of the shadow
68          * object handling in lu_object_find.
69          */
70         if (lov) {
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);
74
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);
80         }
81
82         lu_object_fini(obj);
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);
86         EXIT;
87 }
88
89 static int lovsub_object_print(const struct lu_env *env, void *cookie,
90                                lu_printer_t p, const struct lu_object *obj)
91 {
92         struct lovsub_object *los = lu2lovsub(obj);
93
94         return (*p)(env, cookie, "[%d]", los->lso_index);
95 }
96
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)
100 {
101         struct lovsub_object *los = cl2lovsub(obj);
102         struct lov_object *lov = cl2lovsub(obj)->lso_super;
103
104         ENTRY;
105         lov_r0(lov, lov_comp_entry(los->lso_index))->lo_attr_valid = 0;
106         RETURN(0);
107 }
108
109 static int lovsub_object_glimpse(const struct lu_env *env,
110                                  const struct cl_object *obj,
111                                  struct ost_lvb *lvb)
112 {
113         struct lovsub_object *los = cl2lovsub(obj);
114
115         ENTRY;
116         RETURN(cl_object_glimpse(env, &los->lso_super->lo_cl, lvb));
117 }
118
119 /**
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.
123  */
124 static void lovsub_req_attr_set(const struct lu_env *env, struct cl_object *obj,
125                                 struct cl_req_attr *attr)
126 {
127         struct lovsub_object *subobj = cl2lovsub(obj);
128         struct lov_stripe_md *lsm = subobj->lso_super->lo_lsm;
129
130         ENTRY;
131         cl_req_attr_set(env, &subobj->lso_super->lo_cl, attr);
132
133         /*
134          * There is no OBD_MD_* flag for obdo::o_stripe_idx, so set it
135          * unconditionally. It never changes anyway.
136          */
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;
141         EXIT;
142 }
143
144 static void lovsub_req_projid_set(const struct lu_env *env,
145                                   struct cl_object *obj, __u32 *projid)
146 {
147         struct lovsub_object *subobj = cl2lovsub(obj);
148
149         ENTRY;
150         cl_req_projid_set(env, &subobj->lso_super->lo_cl, projid);
151         EXIT;
152 }
153
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,
159 };
160
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
168 };
169
170 struct lu_object *lovsub_object_alloc(const struct lu_env *env,
171                                       const struct lu_object_header *unused,
172                                       struct lu_device *dev)
173 {
174         struct lovsub_object *los;
175         struct lu_object     *obj;
176
177         ENTRY;
178         OBD_SLAB_ALLOC_PTR_GFP(los, lovsub_object_kmem, GFP_NOFS);
179         if (los) {
180                 struct cl_object_header *hdr;
181
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;
189         } else
190                 obj = NULL;
191         RETURN(obj);
192 }
193
194 /** @} lov */