Whamcloud - gitweb
LU-17160 build: Use PyConfig_InitPythonConfig 3.11 and later
[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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  *
31  * Implementation of cl_device, for OSC layer.
32  *
33  *   Author: Nikita Danilov <nikita.danilov@sun.com>
34  */
35
36 #define DEBUG_SUBSYSTEM S_OSC
37
38 /* class_name2obd() */
39 #include <obd_class.h>
40 #include <lustre_osc.h>
41 #include <uapi/linux/lustre/lustre_param.h>
42
43 #include "osc_internal.h"
44
45 /** \addtogroup osc
46  * @{
47  */
48
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);
53
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_obdo_kmem;
58
59 struct lu_kmem_descr osc_caches[] = {
60         {
61                 .ckd_cache = &osc_lock_kmem,
62                 .ckd_name  = "osc_lock_kmem",
63                 .ckd_size  = sizeof (struct osc_lock)
64         },
65         {
66                 .ckd_cache = &osc_object_kmem,
67                 .ckd_name  = "osc_object_kmem",
68                 .ckd_size  = sizeof (struct osc_object)
69         },
70         {
71                 .ckd_cache = &osc_thread_kmem,
72                 .ckd_name  = "osc_thread_kmem",
73                 .ckd_size  = sizeof (struct osc_thread_info)
74         },
75         {
76                 .ckd_cache = &osc_session_kmem,
77                 .ckd_name  = "osc_session_kmem",
78                 .ckd_size  = sizeof (struct osc_session)
79         },
80         {
81                 .ckd_cache = &osc_extent_kmem,
82                 .ckd_name  = "osc_extent_kmem",
83                 .ckd_size  = sizeof (struct osc_extent)
84         },
85         {
86                 .ckd_cache = &osc_obdo_kmem,
87                 .ckd_name  = "osc_obdo_kmem",
88                 .ckd_size  = sizeof(struct obdo)
89         },
90         {
91                 .ckd_cache = NULL
92         }
93 };
94
95 /*****************************************************************************
96  *
97  * Osc device and device type functions.
98  *
99  */
100
101 static void *osc_key_init(const struct lu_context *ctx,
102                           struct lu_context_key *key)
103 {
104         struct osc_thread_info *info;
105
106         OBD_SLAB_ALLOC_PTR_GFP(info, osc_thread_kmem, GFP_NOFS);
107         if (info == NULL)
108                 info = ERR_PTR(-ENOMEM);
109         return info;
110 }
111
112 static void osc_key_fini(const struct lu_context *ctx,
113                          struct lu_context_key *key, void *data)
114 {
115         struct osc_thread_info *info = data;
116
117         lu_buf_free(&info->oti_ladvise_buf);
118         OBD_SLAB_FREE_PTR(info, osc_thread_kmem);
119 }
120
121 struct lu_context_key osc_key = {
122         .lct_tags = LCT_CL_THREAD,
123         .lct_init = osc_key_init,
124         .lct_fini = osc_key_fini
125 };
126 EXPORT_SYMBOL(osc_key);
127
128 static void *osc_session_init(const struct lu_context *ctx,
129                               struct lu_context_key *key)
130 {
131         struct osc_session *info;
132
133         OBD_SLAB_ALLOC_PTR_GFP(info, osc_session_kmem, GFP_NOFS);
134         if (info == NULL)
135                 info = ERR_PTR(-ENOMEM);
136         return info;
137 }
138
139 static void osc_session_fini(const struct lu_context *ctx,
140                              struct lu_context_key *key, void *data)
141 {
142         struct osc_session *info = data;
143         OBD_SLAB_FREE_PTR(info, osc_session_kmem);
144 }
145
146 struct lu_context_key osc_session_key = {
147         .lct_tags = LCT_SESSION,
148         .lct_init = osc_session_init,
149         .lct_fini = osc_session_fini
150 };
151 EXPORT_SYMBOL(osc_session_key);
152
153 /* type constructor/destructor: osc_type_{init,fini,start,stop}(). */
154 LU_TYPE_INIT_FINI(osc, &osc_key, &osc_session_key);
155
156 static int osc_process_config(const struct lu_env *env, struct lu_device *d,
157                               struct lustre_cfg *cfg)
158 {
159         ssize_t count  = class_modify_config(cfg, PARAM_OSC,
160                                              &d->ld_obd->obd_kset.kobj);
161         return count > 0 ? 0 : count;
162 }
163
164 static const struct lu_device_operations osc_lu_ops = {
165         .ldo_object_alloc      = osc_object_alloc,
166         .ldo_process_config    = osc_process_config,
167         .ldo_recovery_complete = NULL
168 };
169
170 int osc_device_init(const struct lu_env *env, struct lu_device *d,
171                     const char *name, struct lu_device *next)
172 {
173         RETURN(0);
174 }
175 EXPORT_SYMBOL(osc_device_init);
176
177 struct lu_device *osc_device_fini(const struct lu_env *env,
178                                   struct lu_device *d)
179 {
180         return NULL;
181 }
182 EXPORT_SYMBOL(osc_device_fini);
183
184 struct lu_device *osc_device_free(const struct lu_env *env,
185                                   struct lu_device *d)
186 {
187         struct osc_device *oc = lu2osc_dev(d);
188
189         cl_device_fini(lu2cl_dev(d));
190         OBD_FREE_PTR(oc);
191         return NULL;
192 }
193 EXPORT_SYMBOL(osc_device_free);
194
195 static struct lu_device *osc_device_alloc(const struct lu_env *env,
196                                           struct lu_device_type *t,
197                                           struct lustre_cfg *cfg)
198 {
199         struct lu_device *d;
200         struct osc_device *osc;
201         struct obd_device *obd;
202         int rc;
203
204         OBD_ALLOC_PTR(osc);
205         if (osc == NULL)
206                 RETURN(ERR_PTR(-ENOMEM));
207
208         cl_device_init(&osc->osc_cl, t);
209         d = osc2lu_dev(osc);
210         d->ld_ops = &osc_lu_ops;
211
212         /* Setup OSC OBD */
213         obd = class_name2obd(lustre_cfg_string(cfg, 0));
214         LASSERT(obd != NULL);
215         rc = osc_setup(obd, cfg);
216         if (rc) {
217                 osc_device_free(env, d);
218                 RETURN(ERR_PTR(rc));
219         }
220         osc->osc_exp = obd->obd_self_export;
221         osc->osc_stats.os_init = ktime_get_real();
222         RETURN(d);
223 }
224
225 static const struct lu_device_type_operations osc_device_type_ops = {
226         .ldto_init = osc_type_init,
227         .ldto_fini = osc_type_fini,
228
229         .ldto_start = osc_type_start,
230         .ldto_stop  = osc_type_stop,
231
232         .ldto_device_alloc = osc_device_alloc,
233         .ldto_device_free  = osc_device_free,
234
235         .ldto_device_init    = osc_device_init,
236         .ldto_device_fini    = osc_device_fini
237 };
238
239 struct lu_device_type osc_device_type = {
240         .ldt_tags     = LU_DEVICE_CL,
241         .ldt_name     = LUSTRE_OSC_NAME,
242         .ldt_ops      = &osc_device_type_ops,
243         .ldt_ctx_tags = LCT_CL_THREAD
244 };
245
246 /** @} osc */