Whamcloud - gitweb
LU-7734 lnet: set primary NID in ptlrpc_connection_get()
[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, 2015, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * Implementation of cl_object for LOVSUB layer.
33  *
34  *   Author: Nikita Danilov <nikita.danilov@sun.com>
35  */
36
37 #define DEBUG_SUBSYSTEM S_LOV
38
39 #include "lov_cl_internal.h"
40
41 /** \addtogroup lov
42  *  @{
43  */
44
45 /*****************************************************************************
46  *
47  * Lovsub object operations.
48  *
49  */
50
51 int lovsub_object_init(const struct lu_env *env, struct lu_object *obj,
52                        const struct lu_object_conf *conf)
53 {
54         struct lovsub_device  *dev   = lu2lovsub_dev(obj->lo_dev);
55         struct lu_object      *below;
56         struct lu_device      *under;
57
58         int result;
59
60         ENTRY;
61         under = &dev->acid_next->cd_lu_dev;
62         below = under->ld_ops->ldo_object_alloc(env, obj->lo_header, under);
63         if (below != NULL) {
64                 lu_object_add(obj, below);
65                 cl_object_page_init(lu2cl(obj), sizeof(struct lovsub_page));
66                 result = 0;
67         } else
68                 result = -ENOMEM;
69         RETURN(result);
70
71 }
72
73 static void lovsub_object_free(const struct lu_env *env, struct lu_object *obj)
74 {
75         struct lovsub_object *los = lu2lovsub(obj);
76         struct lov_object    *lov = los->lso_super;
77         ENTRY;
78
79         /* We can't assume lov was assigned here, because of the shadow
80          * object handling in lu_object_find.
81          */
82         if (lov) {
83                 LASSERT(lov->lo_type == LLT_RAID0);
84                 LASSERT(lov->u.raid0.lo_sub[los->lso_index] == los);
85                 spin_lock(&lov->u.raid0.lo_sub_lock);
86                 lov->u.raid0.lo_sub[los->lso_index] = NULL;
87                 spin_unlock(&lov->u.raid0.lo_sub_lock);
88         }
89
90         lu_object_fini(obj);
91         lu_object_header_fini(&los->lso_header.coh_lu);
92         OBD_SLAB_FREE_PTR(los, lovsub_object_kmem);
93         EXIT;
94 }
95
96 static int lovsub_object_print(const struct lu_env *env, void *cookie,
97                                lu_printer_t p, const struct lu_object *obj)
98 {
99         struct lovsub_object *los = lu2lovsub(obj);
100
101         return (*p)(env, cookie, "[%d]", los->lso_index);
102 }
103
104 static int lovsub_attr_update(const struct lu_env *env, struct cl_object *obj,
105                               const struct cl_attr *attr, unsigned valid)
106 {
107         struct lov_object *lov = cl2lovsub(obj)->lso_super;
108
109         ENTRY;
110         lov_r0(lov)->lo_attr_valid = 0;
111         RETURN(0);
112 }
113
114 static int lovsub_object_glimpse(const struct lu_env *env,
115                                  const struct cl_object *obj,
116                                  struct ost_lvb *lvb)
117 {
118         struct lovsub_object *los = cl2lovsub(obj);
119
120         ENTRY;
121         RETURN(cl_object_glimpse(env, &los->lso_super->lo_cl, lvb));
122 }
123
124 /**
125  * Implementation of struct cl_object_operations::coo_req_attr_set() for lovsub
126  * layer. Lov and lovsub are responsible only for struct obdo::o_stripe_idx
127  * field, which is filled there.
128  */
129 static void lovsub_req_attr_set(const struct lu_env *env, struct cl_object *obj,
130                                 struct cl_req_attr *attr)
131 {
132         struct lovsub_object *subobj = cl2lovsub(obj);
133
134         ENTRY;
135         cl_req_attr_set(env, &subobj->lso_super->lo_cl, attr);
136
137         /*
138          * There is no OBD_MD_* flag for obdo::o_stripe_idx, so set it
139          * unconditionally. It never changes anyway.
140          */
141         attr->cra_oa->o_stripe_idx = subobj->lso_index;
142         EXIT;
143 }
144
145 static const struct cl_object_operations lovsub_ops = {
146         .coo_page_init    = lovsub_page_init,
147         .coo_lock_init    = lovsub_lock_init,
148         .coo_attr_update  = lovsub_attr_update,
149         .coo_glimpse      = lovsub_object_glimpse,
150         .coo_req_attr_set = lovsub_req_attr_set
151 };
152
153 static const struct lu_object_operations lovsub_lu_obj_ops = {
154         .loo_object_init      = lovsub_object_init,
155         .loo_object_delete    = NULL,
156         .loo_object_release   = NULL,
157         .loo_object_free      = lovsub_object_free,
158         .loo_object_print     = lovsub_object_print,
159         .loo_object_invariant = NULL
160 };
161
162 struct lu_object *lovsub_object_alloc(const struct lu_env *env,
163                                       const struct lu_object_header *unused,
164                                       struct lu_device *dev)
165 {
166         struct lovsub_object *los;
167         struct lu_object     *obj;
168
169         ENTRY;
170         OBD_SLAB_ALLOC_PTR_GFP(los, lovsub_object_kmem, GFP_NOFS);
171         if (los != NULL) {
172                 struct cl_object_header *hdr;
173
174                 obj = lovsub2lu(los);
175                 hdr = &los->lso_header;
176                 cl_object_header_init(hdr);
177                 lu_object_init(obj, &hdr->coh_lu, dev);
178                 lu_object_add_top(&hdr->coh_lu, obj);
179                 los->lso_cl.co_ops = &lovsub_ops;
180                 obj->lo_ops = &lovsub_lu_obj_ops;
181         } else
182                 obj = NULL;
183         RETURN(obj);
184 }
185
186 /** @} lov */