Whamcloud - gitweb
LU-6943 clio: get rid of cl_req
[fs/lustre-release.git] / lustre / lov / lovsub_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.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2013, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * Implementation of cl_device and cl_device_type for LOVSUB layer.
37  *
38  *   Author: Nikita Danilov <nikita.danilov@sun.com>
39  */
40
41 #define DEBUG_SUBSYSTEM S_LOV
42
43 #include "lov_cl_internal.h"
44
45 /** \addtogroup lov
46  *  @{
47  */
48
49 /*****************************************************************************
50  *
51  * Lov-sub device and device type functions.
52  *
53  */
54
55 static int lovsub_device_init(const struct lu_env *env, struct lu_device *d,
56                               const char *name, struct lu_device *next)
57 {
58         struct lovsub_device  *lsd = lu2lovsub_dev(d);
59         struct lu_device_type *ldt;
60         int rc;
61
62         ENTRY;
63         next->ld_site = d->ld_site;
64         ldt = next->ld_type;
65         LASSERT(ldt != NULL);
66         rc = ldt->ldt_ops->ldto_device_init(env, next, ldt->ldt_name, NULL);
67         if (rc) {
68                 next->ld_site = NULL;
69                 RETURN(rc);
70         }
71
72         lu_device_get(next);
73         lu_ref_add(&next->ld_reference, "lu-stack", &lu_site_init);
74         lsd->acid_next = lu2cl_dev(next);
75         RETURN(rc);
76 }
77
78 static struct lu_device *lovsub_device_fini(const struct lu_env *env,
79                                             struct lu_device *d)
80 {
81         struct lu_device *next;
82         struct lovsub_device *lsd;
83
84         ENTRY;
85         lsd = lu2lovsub_dev(d);
86         next = cl2lu_dev(lsd->acid_next);
87         lsd->acid_super = NULL;
88         lsd->acid_next = NULL;
89         RETURN(next);
90 }
91
92 static struct lu_device *lovsub_device_free(const struct lu_env *env,
93                                             struct lu_device *d)
94 {
95         struct lovsub_device *lsd  = lu2lovsub_dev(d);
96         struct lu_device     *next = cl2lu_dev(lsd->acid_next);
97
98         if (atomic_read(&d->ld_ref) && d->ld_site) {
99                 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
100                 lu_site_print(env, d->ld_site, &msgdata, lu_cdebug_printer);
101         }
102         cl_device_fini(lu2cl_dev(d));
103         OBD_FREE_PTR(lsd);
104         return next;
105 }
106
107 static const struct lu_device_operations lovsub_lu_ops = {
108         .ldo_object_alloc      = lovsub_object_alloc,
109         .ldo_process_config    = NULL,
110         .ldo_recovery_complete = NULL
111 };
112
113 static struct lu_device *lovsub_device_alloc(const struct lu_env *env,
114                                              struct lu_device_type *t,
115                                              struct lustre_cfg *cfg)
116 {
117         struct lu_device     *d;
118         struct lovsub_device *lsd;
119
120         OBD_ALLOC_PTR(lsd);
121         if (lsd != NULL) {
122                 int result;
123
124                 result = cl_device_init(&lsd->acid_cl, t);
125                 if (result == 0) {
126                         d = lovsub2lu_dev(lsd);
127                         d->ld_ops         = &lovsub_lu_ops;
128                 } else
129                         d = ERR_PTR(result);
130         } else
131                 d = ERR_PTR(-ENOMEM);
132         return d;
133 }
134
135 static const struct lu_device_type_operations lovsub_device_type_ops = {
136         .ldto_device_alloc = lovsub_device_alloc,
137         .ldto_device_free  = lovsub_device_free,
138
139         .ldto_device_init    = lovsub_device_init,
140         .ldto_device_fini    = lovsub_device_fini
141 };
142
143 #define LUSTRE_LOVSUB_NAME         "lovsub"
144
145 struct lu_device_type lovsub_device_type = {
146         .ldt_tags     = LU_DEVICE_CL,
147         .ldt_name     = LUSTRE_LOVSUB_NAME,
148         .ldt_ops      = &lovsub_device_type_ops,
149         .ldt_ctx_tags = LCT_CL_THREAD
150 };
151
152
153 /** @} lov */
154