1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * Implementation of cl_device, cl_req for OSC layer.
38 * Author: Nikita Danilov <nikita.danilov@sun.com>
41 #define DEBUG_SUBSYSTEM S_OSC
43 /* class_name2obd() */
44 #include <obd_class.h>
46 #include "osc_cl_internal.h"
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;
59 struct lu_kmem_descr osc_caches[] = {
61 .ckd_cache = &osc_page_kmem,
62 .ckd_name = "osc_page_kmem",
63 .ckd_size = sizeof (struct osc_page)
66 .ckd_cache = &osc_lock_kmem,
67 .ckd_name = "osc_lock_kmem",
68 .ckd_size = sizeof (struct osc_lock)
71 .ckd_cache = &osc_object_kmem,
72 .ckd_name = "osc_object_kmem",
73 .ckd_size = sizeof (struct osc_object)
76 .ckd_cache = &osc_thread_kmem,
77 .ckd_name = "osc_thread_kmem",
78 .ckd_size = sizeof (struct osc_thread_info)
81 .ckd_cache = &osc_session_kmem,
82 .ckd_name = "osc_session_kmem",
83 .ckd_size = sizeof (struct osc_session)
86 .ckd_cache = &osc_req_kmem,
87 .ckd_name = "osc_req_kmem",
88 .ckd_size = sizeof (struct osc_req)
95 cfs_lock_class_key_t osc_ast_guard_class;
97 /*****************************************************************************
103 static struct lu_device *osc2lu_dev(struct osc_device *osc)
105 return &osc->od_cl.cd_lu_dev;
108 /*****************************************************************************
110 * Osc device and device type functions.
114 static void *osc_key_init(const struct lu_context *ctx,
115 struct lu_context_key *key)
117 struct osc_thread_info *info;
119 OBD_SLAB_ALLOC_PTR_GFP(info, osc_thread_kmem, CFS_ALLOC_IO);
121 info = ERR_PTR(-ENOMEM);
125 static void osc_key_fini(const struct lu_context *ctx,
126 struct lu_context_key *key, void *data)
128 struct osc_thread_info *info = data;
129 OBD_SLAB_FREE_PTR(info, osc_thread_kmem);
132 struct lu_context_key osc_key = {
133 .lct_tags = LCT_CL_THREAD,
134 .lct_init = osc_key_init,
135 .lct_fini = osc_key_fini
138 static void *osc_session_init(const struct lu_context *ctx,
139 struct lu_context_key *key)
141 struct osc_session *info;
143 OBD_SLAB_ALLOC_PTR_GFP(info, osc_session_kmem, CFS_ALLOC_IO);
145 info = ERR_PTR(-ENOMEM);
149 static void osc_session_fini(const struct lu_context *ctx,
150 struct lu_context_key *key, void *data)
152 struct osc_session *info = data;
153 OBD_SLAB_FREE_PTR(info, osc_session_kmem);
156 struct lu_context_key osc_session_key = {
157 .lct_tags = LCT_SESSION,
158 .lct_init = osc_session_init,
159 .lct_fini = osc_session_fini
162 /* type constructor/destructor: osc_type_{init,fini,start,stop}(). */
163 LU_TYPE_INIT_FINI(osc, &osc_key, &osc_session_key);
165 static int osc_cl_process_config(const struct lu_env *env,
166 struct lu_device *d, struct lustre_cfg *cfg)
169 RETURN(osc_process_config_base(d->ld_obd, cfg));
172 static const struct lu_device_operations osc_lu_ops = {
173 .ldo_object_alloc = osc_object_alloc,
174 .ldo_process_config = osc_cl_process_config,
175 .ldo_recovery_complete = NULL
178 static const struct cl_device_operations osc_cl_ops = {
179 .cdo_req_init = osc_req_init
182 static int osc_device_init(const struct lu_env *env, struct lu_device *d,
183 const char *name, struct lu_device *next)
188 static struct lu_device *osc_device_fini(const struct lu_env *env,
194 static struct lu_device *osc_device_free(const struct lu_env *env,
197 struct osc_device *od = lu2osc_dev(d);
199 cl_device_fini(lu2cl_dev(d));
204 static struct lu_device *osc_device_alloc(const struct lu_env *env,
205 struct lu_device_type *t,
206 struct lustre_cfg *cfg)
209 struct osc_device *od;
210 struct obd_device *obd;
215 RETURN(ERR_PTR(-ENOMEM));
217 cl_device_init(&od->od_cl, t);
219 d->ld_ops = &osc_lu_ops;
220 od->od_cl.cd_ops = &osc_cl_ops;
223 obd = class_name2obd(lustre_cfg_string(cfg, 0));
224 LASSERT(obd != NULL);
225 rc = osc_setup(obd, cfg);
227 osc_device_free(env, d);
230 od->od_exp = obd->obd_self_export;
234 static const struct lu_device_type_operations osc_device_type_ops = {
235 .ldto_init = osc_type_init,
236 .ldto_fini = osc_type_fini,
238 .ldto_start = osc_type_start,
239 .ldto_stop = osc_type_stop,
241 .ldto_device_alloc = osc_device_alloc,
242 .ldto_device_free = osc_device_free,
244 .ldto_device_init = osc_device_init,
245 .ldto_device_fini = osc_device_fini
248 struct lu_device_type osc_device_type = {
249 .ldt_tags = LU_DEVICE_CL,
250 .ldt_name = LUSTRE_OSC_NAME,
251 .ldt_ops = &osc_device_type_ops,
252 .ldt_ctx_tags = LCT_CL_THREAD