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