Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / drivers / staging / lustre / lustre / lov / lovsub_dev.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 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  *
34  * Implementation of cl_device and cl_device_type for LOVSUB layer.
35  *
36  *   Author: Nikita Danilov <nikita.danilov@sun.com>
37  */
38
39 #define DEBUG_SUBSYSTEM S_LOV
40
41 #include "lov_cl_internal.h"
42
43 /** \addtogroup lov
44  *  @{
45  */
46
47 /*****************************************************************************
48  *
49  * Lovsub transfer operations.
50  *
51  */
52
53 static void lovsub_req_completion(const struct lu_env *env,
54                                   const struct cl_req_slice *slice, int ioret)
55 {
56         struct lovsub_req *lsr;
57
58         lsr = cl2lovsub_req(slice);
59         OBD_SLAB_FREE_PTR(lsr, lovsub_req_kmem);
60 }
61
62 /**
63  * Implementation of struct cl_req_operations::cro_attr_set() for lovsub
64  * layer. Lov and lovsub are responsible only for struct obdo::o_stripe_idx
65  * field, which is filled there.
66  */
67 static void lovsub_req_attr_set(const struct lu_env *env,
68                                 const struct cl_req_slice *slice,
69                                 const struct cl_object *obj,
70                                 struct cl_req_attr *attr, u64 flags)
71 {
72         struct lovsub_object *subobj;
73
74         subobj = cl2lovsub(obj);
75         /*
76          * There is no OBD_MD_* flag for obdo::o_stripe_idx, so set it
77          * unconditionally. It never changes anyway.
78          */
79         attr->cra_oa->o_stripe_idx = subobj->lso_index;
80 }
81
82 static const struct cl_req_operations lovsub_req_ops = {
83         .cro_attr_set   = lovsub_req_attr_set,
84         .cro_completion = lovsub_req_completion
85 };
86
87 /*****************************************************************************
88  *
89  * Lov-sub device and device type functions.
90  *
91  */
92
93 static int lovsub_device_init(const struct lu_env *env, struct lu_device *d,
94                               const char *name, struct lu_device *next)
95 {
96         struct lovsub_device  *lsd = lu2lovsub_dev(d);
97         struct lu_device_type *ldt;
98         int rc;
99
100         next->ld_site = d->ld_site;
101         ldt = next->ld_type;
102         LASSERT(ldt != NULL);
103         rc = ldt->ldt_ops->ldto_device_init(env, next, ldt->ldt_name, NULL);
104         if (rc) {
105                 next->ld_site = NULL;
106                 return rc;
107         }
108
109         lu_device_get(next);
110         lu_ref_add(&next->ld_reference, "lu-stack", &lu_site_init);
111         lsd->acid_next = lu2cl_dev(next);
112         return rc;
113 }
114
115 static struct lu_device *lovsub_device_fini(const struct lu_env *env,
116                                             struct lu_device *d)
117 {
118         struct lu_device *next;
119         struct lovsub_device *lsd;
120
121         lsd = lu2lovsub_dev(d);
122         next = cl2lu_dev(lsd->acid_next);
123         lsd->acid_super = NULL;
124         lsd->acid_next = NULL;
125         return next;
126 }
127
128 static struct lu_device *lovsub_device_free(const struct lu_env *env,
129                                             struct lu_device *d)
130 {
131         struct lovsub_device *lsd  = lu2lovsub_dev(d);
132         struct lu_device     *next = cl2lu_dev(lsd->acid_next);
133
134         if (atomic_read(&d->ld_ref) && d->ld_site) {
135                 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
136                 lu_site_print(env, d->ld_site, &msgdata, lu_cdebug_printer);
137         }
138         cl_device_fini(lu2cl_dev(d));
139         OBD_FREE_PTR(lsd);
140         return next;
141 }
142
143 static int lovsub_req_init(const struct lu_env *env, struct cl_device *dev,
144                            struct cl_req *req)
145 {
146         struct lovsub_req *lsr;
147         int result;
148
149         OBD_SLAB_ALLOC_PTR_GFP(lsr, lovsub_req_kmem, GFP_NOFS);
150         if (lsr != NULL) {
151                 cl_req_slice_add(req, &lsr->lsrq_cl, dev, &lovsub_req_ops);
152                 result = 0;
153         } else
154                 result = -ENOMEM;
155         return result;
156 }
157
158 static const struct lu_device_operations lovsub_lu_ops = {
159         .ldo_object_alloc      = lovsub_object_alloc,
160         .ldo_process_config    = NULL,
161         .ldo_recovery_complete = NULL
162 };
163
164 static const struct cl_device_operations lovsub_cl_ops = {
165         .cdo_req_init = lovsub_req_init
166 };
167
168 static struct lu_device *lovsub_device_alloc(const struct lu_env *env,
169                                              struct lu_device_type *t,
170                                              struct lustre_cfg *cfg)
171 {
172         struct lu_device     *d;
173         struct lovsub_device *lsd;
174
175         OBD_ALLOC_PTR(lsd);
176         if (lsd != NULL) {
177                 int result;
178
179                 result = cl_device_init(&lsd->acid_cl, t);
180                 if (result == 0) {
181                         d = lovsub2lu_dev(lsd);
182                         d->ld_ops        = &lovsub_lu_ops;
183                         lsd->acid_cl.cd_ops = &lovsub_cl_ops;
184                 } else
185                         d = ERR_PTR(result);
186         } else
187                 d = ERR_PTR(-ENOMEM);
188         return d;
189 }
190
191 static const struct lu_device_type_operations lovsub_device_type_ops = {
192         .ldto_device_alloc = lovsub_device_alloc,
193         .ldto_device_free  = lovsub_device_free,
194
195         .ldto_device_init    = lovsub_device_init,
196         .ldto_device_fini    = lovsub_device_fini
197 };
198
199 #define LUSTRE_LOVSUB_NAME       "lovsub"
200
201 struct lu_device_type lovsub_device_type = {
202         .ldt_tags     = LU_DEVICE_CL,
203         .ldt_name     = LUSTRE_LOVSUB_NAME,
204         .ldt_ops      = &lovsub_device_type_ops,
205         .ldt_ctx_tags = LCT_CL_THREAD
206 };
207
208
209 /** @} lov */