4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * Implementation of cl_device, cl_req for OSC layer.
34 * Author: Nikita Danilov <nikita.danilov@sun.com>
37 #define DEBUG_SUBSYSTEM S_OSC
39 /* class_name2obd() */
40 #include "../include/obd_class.h"
42 #include "osc_cl_internal.h"
48 struct kmem_cache *osc_lock_kmem;
49 struct kmem_cache *osc_object_kmem;
50 struct kmem_cache *osc_thread_kmem;
51 struct kmem_cache *osc_session_kmem;
52 struct kmem_cache *osc_req_kmem;
53 struct kmem_cache *osc_extent_kmem;
54 struct kmem_cache *osc_quota_kmem;
56 struct lu_kmem_descr osc_caches[] = {
58 .ckd_cache = &osc_lock_kmem,
59 .ckd_name = "osc_lock_kmem",
60 .ckd_size = sizeof(struct osc_lock)
63 .ckd_cache = &osc_object_kmem,
64 .ckd_name = "osc_object_kmem",
65 .ckd_size = sizeof(struct osc_object)
68 .ckd_cache = &osc_thread_kmem,
69 .ckd_name = "osc_thread_kmem",
70 .ckd_size = sizeof(struct osc_thread_info)
73 .ckd_cache = &osc_session_kmem,
74 .ckd_name = "osc_session_kmem",
75 .ckd_size = sizeof(struct osc_session)
78 .ckd_cache = &osc_req_kmem,
79 .ckd_name = "osc_req_kmem",
80 .ckd_size = sizeof(struct osc_req)
83 .ckd_cache = &osc_extent_kmem,
84 .ckd_name = "osc_extent_kmem",
85 .ckd_size = sizeof(struct osc_extent)
88 .ckd_cache = &osc_quota_kmem,
89 .ckd_name = "osc_quota_kmem",
90 .ckd_size = sizeof(struct osc_quota_info)
97 struct lock_class_key osc_ast_guard_class;
99 /*****************************************************************************
105 static struct lu_device *osc2lu_dev(struct osc_device *osc)
107 return &osc->od_cl.cd_lu_dev;
110 /*****************************************************************************
112 * Osc device and device type functions.
116 static void *osc_key_init(const struct lu_context *ctx,
117 struct lu_context_key *key)
119 struct osc_thread_info *info;
121 info = kmem_cache_zalloc(osc_thread_kmem, GFP_NOFS);
123 info = ERR_PTR(-ENOMEM);
127 static void osc_key_fini(const struct lu_context *ctx,
128 struct lu_context_key *key, void *data)
130 struct osc_thread_info *info = data;
132 kmem_cache_free(osc_thread_kmem, info);
135 struct lu_context_key osc_key = {
136 .lct_tags = LCT_CL_THREAD,
137 .lct_init = osc_key_init,
138 .lct_fini = osc_key_fini
141 static void *osc_session_init(const struct lu_context *ctx,
142 struct lu_context_key *key)
144 struct osc_session *info;
146 info = kmem_cache_zalloc(osc_session_kmem, GFP_NOFS);
148 info = ERR_PTR(-ENOMEM);
152 static void osc_session_fini(const struct lu_context *ctx,
153 struct lu_context_key *key, void *data)
155 struct osc_session *info = data;
157 kmem_cache_free(osc_session_kmem, info);
160 struct lu_context_key osc_session_key = {
161 .lct_tags = LCT_SESSION,
162 .lct_init = osc_session_init,
163 .lct_fini = osc_session_fini
166 /* type constructor/destructor: osc_type_{init,fini,start,stop}(). */
167 LU_TYPE_INIT_FINI(osc, &osc_key, &osc_session_key);
169 static int osc_cl_process_config(const struct lu_env *env,
170 struct lu_device *d, struct lustre_cfg *cfg)
172 return osc_process_config_base(d->ld_obd, cfg);
175 static const struct lu_device_operations osc_lu_ops = {
176 .ldo_object_alloc = osc_object_alloc,
177 .ldo_process_config = osc_cl_process_config,
178 .ldo_recovery_complete = NULL
181 static const struct cl_device_operations osc_cl_ops = {
182 .cdo_req_init = osc_req_init
185 static int osc_device_init(const struct lu_env *env, struct lu_device *d,
186 const char *name, struct lu_device *next)
191 static struct lu_device *osc_device_fini(const struct lu_env *env,
197 static struct lu_device *osc_device_free(const struct lu_env *env,
200 struct osc_device *od = lu2osc_dev(d);
202 cl_device_fini(lu2cl_dev(d));
207 static struct lu_device *osc_device_alloc(const struct lu_env *env,
208 struct lu_device_type *t,
209 struct lustre_cfg *cfg)
212 struct osc_device *od;
213 struct obd_device *obd;
216 od = kzalloc(sizeof(*od), GFP_NOFS);
218 return ERR_PTR(-ENOMEM);
220 cl_device_init(&od->od_cl, t);
222 d->ld_ops = &osc_lu_ops;
223 od->od_cl.cd_ops = &osc_cl_ops;
226 obd = class_name2obd(lustre_cfg_string(cfg, 0));
228 rc = osc_setup(obd, cfg);
230 osc_device_free(env, d);
233 od->od_exp = obd->obd_self_export;
237 static const struct lu_device_type_operations osc_device_type_ops = {
238 .ldto_init = osc_type_init,
239 .ldto_fini = osc_type_fini,
241 .ldto_start = osc_type_start,
242 .ldto_stop = osc_type_stop,
244 .ldto_device_alloc = osc_device_alloc,
245 .ldto_device_free = osc_device_free,
247 .ldto_device_init = osc_device_init,
248 .ldto_device_fini = osc_device_fini
251 struct lu_device_type osc_device_type = {
252 .ldt_tags = LU_DEVICE_CL,
253 .ldt_name = LUSTRE_OSC_NAME,
254 .ldt_ops = &osc_device_type_ops,
255 .ldt_ctx_tags = LCT_CL_THREAD