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, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * Implementation of cl_device, for OSC layer.
33 * Author: Nikita Danilov <nikita.danilov@sun.com>
36 #define DEBUG_SUBSYSTEM S_OSC
38 /* class_name2obd() */
39 #include <obd_class.h>
40 #include <lustre_osc.h>
41 #include <uapi/linux/lustre/lustre_param.h>
43 #include "osc_internal.h"
49 struct kmem_cache *osc_lock_kmem;
50 EXPORT_SYMBOL(osc_lock_kmem);
51 struct kmem_cache *osc_object_kmem;
52 EXPORT_SYMBOL(osc_object_kmem);
54 struct kmem_cache *osc_thread_kmem;
55 struct kmem_cache *osc_session_kmem;
56 struct kmem_cache *osc_extent_kmem;
57 struct kmem_cache *osc_quota_kmem;
58 struct kmem_cache *osc_obdo_kmem;
60 struct lu_kmem_descr osc_caches[] = {
62 .ckd_cache = &osc_lock_kmem,
63 .ckd_name = "osc_lock_kmem",
64 .ckd_size = sizeof (struct osc_lock)
67 .ckd_cache = &osc_object_kmem,
68 .ckd_name = "osc_object_kmem",
69 .ckd_size = sizeof (struct osc_object)
72 .ckd_cache = &osc_thread_kmem,
73 .ckd_name = "osc_thread_kmem",
74 .ckd_size = sizeof (struct osc_thread_info)
77 .ckd_cache = &osc_session_kmem,
78 .ckd_name = "osc_session_kmem",
79 .ckd_size = sizeof (struct osc_session)
82 .ckd_cache = &osc_extent_kmem,
83 .ckd_name = "osc_extent_kmem",
84 .ckd_size = sizeof (struct osc_extent)
87 .ckd_cache = &osc_quota_kmem,
88 .ckd_name = "osc_quota_kmem",
89 .ckd_size = sizeof(struct osc_quota_info)
92 .ckd_cache = &osc_obdo_kmem,
93 .ckd_name = "osc_obdo_kmem",
94 .ckd_size = sizeof(struct obdo)
101 /*****************************************************************************
103 * Osc device and device type functions.
107 static void *osc_key_init(const struct lu_context *ctx,
108 struct lu_context_key *key)
110 struct osc_thread_info *info;
112 OBD_SLAB_ALLOC_PTR_GFP(info, osc_thread_kmem, GFP_NOFS);
114 info = ERR_PTR(-ENOMEM);
118 static void osc_key_fini(const struct lu_context *ctx,
119 struct lu_context_key *key, void *data)
121 struct osc_thread_info *info = data;
123 lu_buf_free(&info->oti_ladvise_buf);
124 OBD_SLAB_FREE_PTR(info, osc_thread_kmem);
127 struct lu_context_key osc_key = {
128 .lct_tags = LCT_CL_THREAD,
129 .lct_init = osc_key_init,
130 .lct_fini = osc_key_fini
132 EXPORT_SYMBOL(osc_key);
134 static void *osc_session_init(const struct lu_context *ctx,
135 struct lu_context_key *key)
137 struct osc_session *info;
139 OBD_SLAB_ALLOC_PTR_GFP(info, osc_session_kmem, GFP_NOFS);
141 info = ERR_PTR(-ENOMEM);
145 static void osc_session_fini(const struct lu_context *ctx,
146 struct lu_context_key *key, void *data)
148 struct osc_session *info = data;
149 OBD_SLAB_FREE_PTR(info, osc_session_kmem);
152 struct lu_context_key osc_session_key = {
153 .lct_tags = LCT_SESSION,
154 .lct_init = osc_session_init,
155 .lct_fini = osc_session_fini
157 EXPORT_SYMBOL(osc_session_key);
159 /* type constructor/destructor: osc_type_{init,fini,start,stop}(). */
160 LU_TYPE_INIT_FINI(osc, &osc_key, &osc_session_key);
162 static int osc_process_config(const struct lu_env *env, struct lu_device *d,
163 struct lustre_cfg *cfg)
165 ssize_t count = class_modify_config(cfg, PARAM_OSC,
166 &d->ld_obd->obd_kset.kobj);
167 return count > 0 ? 0 : count;
170 static const struct lu_device_operations osc_lu_ops = {
171 .ldo_object_alloc = osc_object_alloc,
172 .ldo_process_config = osc_process_config,
173 .ldo_recovery_complete = NULL
176 int osc_device_init(const struct lu_env *env, struct lu_device *d,
177 const char *name, struct lu_device *next)
181 EXPORT_SYMBOL(osc_device_init);
183 struct lu_device *osc_device_fini(const struct lu_env *env,
188 EXPORT_SYMBOL(osc_device_fini);
190 struct lu_device *osc_device_free(const struct lu_env *env,
193 struct osc_device *od = lu2osc_dev(d);
195 cl_device_fini(lu2cl_dev(d));
199 EXPORT_SYMBOL(osc_device_free);
201 static struct lu_device *osc_device_alloc(const struct lu_env *env,
202 struct lu_device_type *t,
203 struct lustre_cfg *cfg)
206 struct osc_device *od;
207 struct obd_device *obd;
212 RETURN(ERR_PTR(-ENOMEM));
214 cl_device_init(&od->od_cl, t);
216 d->ld_ops = &osc_lu_ops;
219 obd = class_name2obd(lustre_cfg_string(cfg, 0));
220 LASSERT(obd != NULL);
221 rc = osc_setup(obd, cfg);
223 osc_device_free(env, d);
226 od->od_exp = obd->obd_self_export;
230 static const struct lu_device_type_operations osc_device_type_ops = {
231 .ldto_init = osc_type_init,
232 .ldto_fini = osc_type_fini,
234 .ldto_start = osc_type_start,
235 .ldto_stop = osc_type_stop,
237 .ldto_device_alloc = osc_device_alloc,
238 .ldto_device_free = osc_device_free,
240 .ldto_device_init = osc_device_init,
241 .ldto_device_fini = osc_device_fini
244 struct lu_device_type osc_device_type = {
245 .ldt_tags = LU_DEVICE_CL,
246 .ldt_name = LUSTRE_OSC_NAME,
247 .ldt_ops = &osc_device_type_ops,
248 .ldt_ctx_tags = LCT_CL_THREAD