Whamcloud - gitweb
LU-7931 tests: setup/cleanup after every test script
[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.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, 2015, Intel Corporation.
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
46  *  @{
47  */
48
49 /*****************************************************************************
50  *
51  * Lovsub object operations.
52  *
53  */
54
55 int lovsub_object_init(const struct lu_env *env, struct lu_object *obj,
56                        const struct lu_object_conf *conf)
57 {
58         struct lovsub_device  *dev   = lu2lovsub_dev(obj->lo_dev);
59         struct lu_object      *below;
60         struct lu_device      *under;
61
62         int result;
63
64         ENTRY;
65         under = &dev->acid_next->cd_lu_dev;
66         below = under->ld_ops->ldo_object_alloc(env, obj->lo_header, under);
67         if (below != NULL) {
68                 lu_object_add(obj, below);
69                 cl_object_page_init(lu2cl(obj), sizeof(struct lovsub_page));
70                 result = 0;
71         } else
72                 result = -ENOMEM;
73         RETURN(result);
74
75 }
76
77 static void lovsub_object_free(const struct lu_env *env, struct lu_object *obj)
78 {
79         struct lovsub_object *los = lu2lovsub(obj);
80         struct lov_object    *lov = los->lso_super;
81         ENTRY;
82
83         /* We can't assume lov was assigned here, because of the shadow
84          * object handling in lu_object_find.
85          */
86         if (lov) {
87                 LASSERT(lov->lo_type == LLT_RAID0);
88                 LASSERT(lov->u.raid0.lo_sub[los->lso_index] == los);
89                 spin_lock(&lov->u.raid0.lo_sub_lock);
90                 lov->u.raid0.lo_sub[los->lso_index] = NULL;
91                 spin_unlock(&lov->u.raid0.lo_sub_lock);
92         }
93
94         lu_object_fini(obj);
95         lu_object_header_fini(&los->lso_header.coh_lu);
96         OBD_SLAB_FREE_PTR(los, lovsub_object_kmem);
97         EXIT;
98 }
99
100 static int lovsub_object_print(const struct lu_env *env, void *cookie,
101                                lu_printer_t p, const struct lu_object *obj)
102 {
103         struct lovsub_object *los = lu2lovsub(obj);
104
105         return (*p)(env, cookie, "[%d]", los->lso_index);
106 }
107
108 static int lovsub_attr_update(const struct lu_env *env, struct cl_object *obj,
109                               const struct cl_attr *attr, unsigned valid)
110 {
111         struct lov_object *lov = cl2lovsub(obj)->lso_super;
112
113         ENTRY;
114         lov_r0(lov)->lo_attr_valid = 0;
115         RETURN(0);
116 }
117
118 static int lovsub_object_glimpse(const struct lu_env *env,
119                                  const struct cl_object *obj,
120                                  struct ost_lvb *lvb)
121 {
122         struct lovsub_object *los = cl2lovsub(obj);
123
124         ENTRY;
125         RETURN(cl_object_glimpse(env, &los->lso_super->lo_cl, lvb));
126 }
127
128 /**
129  * Implementation of struct cl_object_operations::coo_req_attr_set() for lovsub
130  * layer. Lov and lovsub are responsible only for struct obdo::o_stripe_idx
131  * field, which is filled there.
132  */
133 static void lovsub_req_attr_set(const struct lu_env *env, struct cl_object *obj,
134                                 struct cl_req_attr *attr)
135 {
136         struct lovsub_object *subobj = cl2lovsub(obj);
137
138         ENTRY;
139         cl_req_attr_set(env, &subobj->lso_super->lo_cl, attr);
140
141         /*
142          * There is no OBD_MD_* flag for obdo::o_stripe_idx, so set it
143          * unconditionally. It never changes anyway.
144          */
145         attr->cra_oa->o_stripe_idx = subobj->lso_index;
146         EXIT;
147 }
148
149 static const struct cl_object_operations lovsub_ops = {
150         .coo_page_init    = lovsub_page_init,
151         .coo_lock_init    = lovsub_lock_init,
152         .coo_attr_update  = lovsub_attr_update,
153         .coo_glimpse      = lovsub_object_glimpse,
154         .coo_req_attr_set = lovsub_req_attr_set
155 };
156
157 static const struct lu_object_operations lovsub_lu_obj_ops = {
158         .loo_object_init      = lovsub_object_init,
159         .loo_object_delete    = NULL,
160         .loo_object_release   = NULL,
161         .loo_object_free      = lovsub_object_free,
162         .loo_object_print     = lovsub_object_print,
163         .loo_object_invariant = NULL
164 };
165
166 struct lu_object *lovsub_object_alloc(const struct lu_env *env,
167                                       const struct lu_object_header *unused,
168                                       struct lu_device *dev)
169 {
170         struct lovsub_object *los;
171         struct lu_object     *obj;
172
173         ENTRY;
174         OBD_SLAB_ALLOC_PTR_GFP(los, lovsub_object_kmem, GFP_NOFS);
175         if (los != NULL) {
176                 struct cl_object_header *hdr;
177
178                 obj = lovsub2lu(los);
179                 hdr = &los->lso_header;
180                 cl_object_header_init(hdr);
181                 lu_object_init(obj, &hdr->coh_lu, dev);
182                 lu_object_add_top(&hdr->coh_lu, obj);
183                 los->lso_cl.co_ops = &lovsub_ops;
184                 obj->lo_ops = &lovsub_lu_obj_ops;
185         } else
186                 obj = NULL;
187         RETURN(obj);
188 }
189
190 /** @} lov */