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) 2017 Intel Corporation.
26 * This file is part of Lustre, http://www.lustre.org/
28 * Implementation of cl_device, cl_req for MDC layer.
30 * Author: Mikhail Pershin <mike.pershin@intel.com>
33 #define DEBUG_SUBSYSTEM S_MDC
35 #include <obd_class.h>
36 #include <lustre_osc.h>
38 #include "mdc_internal.h"
40 int mdc_page_init(const struct lu_env *env, struct cl_object *obj,
41 struct cl_page *page, pgoff_t index)
46 int mdc_lock_init(const struct lu_env *env,
47 struct cl_object *obj, struct cl_lock *lock,
48 const struct cl_io *unused)
53 int mdc_io_init(const struct lu_env *env,
54 struct cl_object *obj, struct cl_io *io)
60 * Implementation of struct cl_req_operations::cro_attr_set() for MDC
61 * layer. MDC is responsible for struct obdo::o_id and struct obdo::o_seq
64 static void mdc_req_attr_set(const struct lu_env *env, struct cl_object *obj,
65 struct cl_req_attr *attr)
67 u64 flags = attr->cra_flags;
69 /* Copy object FID to cl_attr */
70 attr->cra_oa->o_oi.oi_fid = *lu_object_fid(&obj->co_lu);
72 if (flags & OBD_MD_FLGROUP)
73 attr->cra_oa->o_valid |= OBD_MD_FLGROUP;
75 if (flags & OBD_MD_FLID)
76 attr->cra_oa->o_valid |= OBD_MD_FLID;
79 static const struct cl_object_operations mdc_ops = {
80 .coo_page_init = mdc_page_init,
81 .coo_lock_init = mdc_lock_init,
82 .coo_io_init = mdc_io_init,
83 .coo_attr_get = osc_attr_get,
84 .coo_attr_update = osc_attr_update,
85 .coo_glimpse = osc_object_glimpse,
86 .coo_req_attr_set = mdc_req_attr_set,
89 static int mdc_object_init(const struct lu_env *env, struct lu_object *obj,
90 const struct lu_object_conf *conf)
92 struct osc_object *osc = lu2osc(obj);
94 if (osc->oo_initialized)
97 osc->oo_initialized = true;
99 return osc_object_init(env, obj, conf);
102 static void mdc_object_free(const struct lu_env *env, struct lu_object *obj)
104 osc_object_free(env, obj);
107 static const struct lu_object_operations mdc_lu_obj_ops = {
108 .loo_object_init = mdc_object_init,
109 .loo_object_delete = NULL,
110 .loo_object_release = NULL,
111 .loo_object_free = mdc_object_free,
112 .loo_object_print = osc_object_print,
113 .loo_object_invariant = NULL
116 struct lu_object *mdc_object_alloc(const struct lu_env *env,
117 const struct lu_object_header *unused,
118 struct lu_device *dev)
120 struct osc_object *osc;
121 struct lu_object *obj;
123 OBD_SLAB_ALLOC_PTR_GFP(osc, osc_object_kmem, GFP_NOFS);
126 lu_object_init(obj, NULL, dev);
127 osc->oo_cl.co_ops = &mdc_ops;
128 obj->lo_ops = &mdc_lu_obj_ops;
129 osc->oo_initialized = false;
136 static int mdc_cl_process_config(const struct lu_env *env,
137 struct lu_device *d, struct lustre_cfg *cfg)
139 return mdc_process_config(d->ld_obd, 0, cfg);
142 const struct lu_device_operations mdc_lu_ops = {
143 .ldo_object_alloc = mdc_object_alloc,
144 .ldo_process_config = mdc_cl_process_config,
145 .ldo_recovery_complete = NULL,
148 static struct lu_device *mdc_device_alloc(const struct lu_env *env,
149 struct lu_device_type *t,
150 struct lustre_cfg *cfg)
153 struct osc_device *od;
154 struct obd_device *obd;
159 RETURN(ERR_PTR(-ENOMEM));
161 cl_device_init(&od->od_cl, t);
163 d->ld_ops = &mdc_lu_ops;
166 obd = class_name2obd(lustre_cfg_string(cfg, 0));
168 RETURN(ERR_PTR(-ENODEV));
170 rc = mdc_setup(obd, cfg);
172 osc_device_free(env, d);
175 od->od_exp = obd->obd_self_export;
179 static const struct lu_device_type_operations mdc_device_type_ops = {
180 .ldto_device_alloc = mdc_device_alloc,
181 .ldto_device_free = osc_device_free,
182 .ldto_device_init = osc_device_init,
183 .ldto_device_fini = osc_device_fini
186 struct lu_device_type mdc_device_type = {
187 .ldt_tags = LU_DEVICE_CL,
188 .ldt_name = LUSTRE_MDC_NAME,
189 .ldt_ops = &mdc_device_type_ops,
190 .ldt_ctx_tags = LCT_CL_THREAD