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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * Implementation of cl_device and cl_device_type for LOVSUB layer.
36 * Author: Nikita Danilov <nikita.danilov@sun.com>
39 #define DEBUG_SUBSYSTEM S_LOV
41 #include "lov_cl_internal.h"
47 /*****************************************************************************
49 * Lovsub transfer operations.
53 static void lovsub_req_completion(const struct lu_env *env,
54 const struct cl_req_slice *slice, int ioret)
56 struct lovsub_req *lsr;
59 lsr = cl2lovsub_req(slice);
60 OBD_SLAB_FREE_PTR(lsr, lovsub_req_kmem);
65 * Implementation of struct cl_req_operations::cro_attr_set() for lovsub
66 * layer. Lov and lovsub are responsible only for struct obdo::o_stripe_idx
67 * field, which is filled there.
69 static void lovsub_req_attr_set(const struct lu_env *env,
70 const struct cl_req_slice *slice,
71 const struct cl_object *obj,
72 struct cl_req_attr *attr, obd_valid flags)
74 struct lovsub_object *subobj;
77 subobj = cl2lovsub(obj);
79 * There is no OBD_MD_* flag for obdo::o_stripe_idx, so set it
80 * unconditionally. It never changes anyway.
82 attr->cra_oa->o_stripe_idx = subobj->lso_index;
86 static const struct cl_req_operations lovsub_req_ops = {
87 .cro_attr_set = lovsub_req_attr_set,
88 .cro_completion = lovsub_req_completion
91 /*****************************************************************************
93 * Lov-sub device and device type functions.
97 static int lovsub_device_init(const struct lu_env *env, struct lu_device *d,
98 const char *name, struct lu_device *next)
100 struct lovsub_device *lsd = lu2lovsub_dev(d);
101 struct lu_device_type *ldt;
105 next->ld_site = d->ld_site;
107 LASSERT(ldt != NULL);
108 rc = ldt->ldt_ops->ldto_device_init(env, next, ldt->ldt_name, NULL);
110 next->ld_site = NULL;
115 lu_ref_add(&next->ld_reference, "lu-stack", &lu_site_init);
116 lsd->acid_next = lu2cl_dev(next);
120 static struct lu_device *lovsub_device_fini(const struct lu_env *env,
123 struct lu_device *next;
124 struct lovsub_device *lsd;
127 lsd = lu2lovsub_dev(d);
128 next = cl2lu_dev(lsd->acid_next);
129 lsd->acid_super = NULL;
130 lsd->acid_next = NULL;
134 static struct lu_device *lovsub_device_free(const struct lu_env *env,
137 struct lovsub_device *lsd = lu2lovsub_dev(d);
138 struct lu_device *next = cl2lu_dev(lsd->acid_next);
140 if (cfs_atomic_read(&d->ld_ref) && d->ld_site) {
141 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
142 lu_site_print(env, d->ld_site, &msgdata, lu_cdebug_printer);
144 cl_device_fini(lu2cl_dev(d));
149 static int lovsub_req_init(const struct lu_env *env, struct cl_device *dev,
152 struct lovsub_req *lsr;
155 OBD_SLAB_ALLOC_PTR_GFP(lsr, lovsub_req_kmem, __GFP_IO);
157 cl_req_slice_add(req, &lsr->lsrq_cl, dev, &lovsub_req_ops);
164 static const struct lu_device_operations lovsub_lu_ops = {
165 .ldo_object_alloc = lovsub_object_alloc,
166 .ldo_process_config = NULL,
167 .ldo_recovery_complete = NULL
170 static const struct cl_device_operations lovsub_cl_ops = {
171 .cdo_req_init = lovsub_req_init
174 static struct lu_device *lovsub_device_alloc(const struct lu_env *env,
175 struct lu_device_type *t,
176 struct lustre_cfg *cfg)
179 struct lovsub_device *lsd;
185 result = cl_device_init(&lsd->acid_cl, t);
187 d = lovsub2lu_dev(lsd);
188 d->ld_ops = &lovsub_lu_ops;
189 lsd->acid_cl.cd_ops = &lovsub_cl_ops;
193 d = ERR_PTR(-ENOMEM);
197 static const struct lu_device_type_operations lovsub_device_type_ops = {
198 .ldto_device_alloc = lovsub_device_alloc,
199 .ldto_device_free = lovsub_device_free,
201 .ldto_device_init = lovsub_device_init,
202 .ldto_device_fini = lovsub_device_fini
205 #define LUSTRE_LOVSUB_NAME "lovsub"
207 struct lu_device_type lovsub_device_type = {
208 .ldt_tags = LU_DEVICE_CL,
209 .ldt_name = LUSTRE_LOVSUB_NAME,
210 .ldt_ops = &lovsub_device_type_ops,
211 .ldt_ctx_tags = LCT_CL_THREAD