Whamcloud - gitweb
LU-2446 build: Update Whamcloud copyright messages for Intel
[fs/lustre-release.git] / lustre / osc / osc_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  * Copyright (c) 2012, 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_device, cl_req for OSC layer.
37  *
38  *   Author: Nikita Danilov <nikita.danilov@sun.com>
39  */
40
41 #define DEBUG_SUBSYSTEM S_OSC
42
43 /* class_name2obd() */
44 #include <obd_class.h>
45
46 #include "osc_cl_internal.h"
47
48 /** \addtogroup osc 
49  * @{ 
50  */
51
52 cfs_mem_cache_t *osc_page_kmem;
53 cfs_mem_cache_t *osc_lock_kmem;
54 cfs_mem_cache_t *osc_object_kmem;
55 cfs_mem_cache_t *osc_thread_kmem;
56 cfs_mem_cache_t *osc_session_kmem;
57 cfs_mem_cache_t *osc_req_kmem;
58 cfs_mem_cache_t *osc_extent_kmem;
59 cfs_mem_cache_t *osc_quota_kmem;
60
61 struct lu_kmem_descr osc_caches[] = {
62         {
63                 .ckd_cache = &osc_page_kmem,
64                 .ckd_name  = "osc_page_kmem",
65                 .ckd_size  = sizeof (struct osc_page)
66         },
67         {
68                 .ckd_cache = &osc_lock_kmem,
69                 .ckd_name  = "osc_lock_kmem",
70                 .ckd_size  = sizeof (struct osc_lock)
71         },
72         {
73                 .ckd_cache = &osc_object_kmem,
74                 .ckd_name  = "osc_object_kmem",
75                 .ckd_size  = sizeof (struct osc_object)
76         },
77         {
78                 .ckd_cache = &osc_thread_kmem,
79                 .ckd_name  = "osc_thread_kmem",
80                 .ckd_size  = sizeof (struct osc_thread_info)
81         },
82         {
83                 .ckd_cache = &osc_session_kmem,
84                 .ckd_name  = "osc_session_kmem",
85                 .ckd_size  = sizeof (struct osc_session)
86         },
87         {
88                 .ckd_cache = &osc_req_kmem,
89                 .ckd_name  = "osc_req_kmem",
90                 .ckd_size  = sizeof (struct osc_req)
91         },
92         {
93                 .ckd_cache = &osc_extent_kmem,
94                 .ckd_name  = "osc_extent_kmem",
95                 .ckd_size  = sizeof (struct osc_extent)
96         },
97         {
98                 .ckd_cache = &osc_quota_kmem,
99                 .ckd_name  = "osc_quota_kmem",
100                 .ckd_size  = sizeof(struct osc_quota_info)
101         },
102         {
103                 .ckd_cache = NULL
104         }
105 };
106
107 struct lock_class_key osc_ast_guard_class;
108
109 /*****************************************************************************
110  *
111  * Type conversions.
112  *
113  */
114
115 static struct lu_device *osc2lu_dev(struct osc_device *osc)
116 {
117         return &osc->od_cl.cd_lu_dev;
118 }
119
120 /*****************************************************************************
121  *
122  * Osc device and device type functions.
123  *
124  */
125
126 static void *osc_key_init(const struct lu_context *ctx,
127                          struct lu_context_key *key)
128 {
129         struct osc_thread_info *info;
130
131         OBD_SLAB_ALLOC_PTR_GFP(info, osc_thread_kmem, CFS_ALLOC_IO);
132         if (info == NULL)
133                 info = ERR_PTR(-ENOMEM);
134         return info;
135 }
136
137 static void osc_key_fini(const struct lu_context *ctx,
138                          struct lu_context_key *key, void *data)
139 {
140         struct osc_thread_info *info = data;
141         OBD_SLAB_FREE_PTR(info, osc_thread_kmem);
142 }
143
144 struct lu_context_key osc_key = {
145         .lct_tags = LCT_CL_THREAD,
146         .lct_init = osc_key_init,
147         .lct_fini = osc_key_fini
148 };
149
150 static void *osc_session_init(const struct lu_context *ctx,
151                               struct lu_context_key *key)
152 {
153         struct osc_session *info;
154
155         OBD_SLAB_ALLOC_PTR_GFP(info, osc_session_kmem, CFS_ALLOC_IO);
156         if (info == NULL)
157                 info = ERR_PTR(-ENOMEM);
158         return info;
159 }
160
161 static void osc_session_fini(const struct lu_context *ctx,
162                              struct lu_context_key *key, void *data)
163 {
164         struct osc_session *info = data;
165         OBD_SLAB_FREE_PTR(info, osc_session_kmem);
166 }
167
168 struct lu_context_key osc_session_key = {
169         .lct_tags = LCT_SESSION,
170         .lct_init = osc_session_init,
171         .lct_fini = osc_session_fini
172 };
173
174 /* type constructor/destructor: osc_type_{init,fini,start,stop}(). */
175 LU_TYPE_INIT_FINI(osc, &osc_key, &osc_session_key);
176
177 static int osc_cl_process_config(const struct lu_env *env,
178                                  struct lu_device *d, struct lustre_cfg *cfg)
179 {
180         ENTRY;
181         RETURN(osc_process_config_base(d->ld_obd, cfg));
182 }
183
184 static const struct lu_device_operations osc_lu_ops = {
185         .ldo_object_alloc      = osc_object_alloc,
186         .ldo_process_config    = osc_cl_process_config,
187         .ldo_recovery_complete = NULL
188 };
189
190 static const struct cl_device_operations osc_cl_ops = {
191         .cdo_req_init = osc_req_init
192 };
193
194 static int osc_device_init(const struct lu_env *env, struct lu_device *d,
195                            const char *name, struct lu_device *next)
196 {
197         RETURN(0);
198 }
199
200 static struct lu_device *osc_device_fini(const struct lu_env *env,
201                                          struct lu_device *d)
202 {
203         return 0;
204 }
205
206 static struct lu_device *osc_device_free(const struct lu_env *env,
207                                          struct lu_device *d)
208 {
209         struct osc_device *od = lu2osc_dev(d);
210
211         cl_device_fini(lu2cl_dev(d));
212         OBD_FREE_PTR(od);
213         return NULL;
214 }
215
216 static struct lu_device *osc_device_alloc(const struct lu_env *env,
217                                           struct lu_device_type *t,
218                                           struct lustre_cfg *cfg)
219 {
220         struct lu_device *d;
221         struct osc_device *od;
222         struct obd_device *obd;
223         int rc;
224
225         OBD_ALLOC_PTR(od);
226         if (od == NULL)
227                 RETURN(ERR_PTR(-ENOMEM));
228
229         cl_device_init(&od->od_cl, t);
230         d = osc2lu_dev(od);
231         d->ld_ops = &osc_lu_ops;
232         od->od_cl.cd_ops = &osc_cl_ops;
233
234         /* Setup OSC OBD */
235         obd = class_name2obd(lustre_cfg_string(cfg, 0));
236         LASSERT(obd != NULL);
237         rc = osc_setup(obd, cfg);
238         if (rc) {
239                 osc_device_free(env, d);
240                 RETURN(ERR_PTR(rc));
241         }
242         od->od_exp = obd->obd_self_export;
243         RETURN(d);
244 }
245
246 static const struct lu_device_type_operations osc_device_type_ops = {
247         .ldto_init = osc_type_init,
248         .ldto_fini = osc_type_fini,
249
250         .ldto_start = osc_type_start,
251         .ldto_stop  = osc_type_stop,
252
253         .ldto_device_alloc = osc_device_alloc,
254         .ldto_device_free  = osc_device_free,
255
256         .ldto_device_init    = osc_device_init,
257         .ldto_device_fini    = osc_device_fini
258 };
259
260 struct lu_device_type osc_device_type = {
261         .ldt_tags     = LU_DEVICE_CL,
262         .ldt_name     = LUSTRE_OSC_NAME,
263         .ldt_ops      = &osc_device_type_ops,
264         .ldt_ctx_tags = LCT_CL_THREAD
265 };
266
267 /** @} osc */