Whamcloud - gitweb
LU-16974 utils: make bandwidth options consistent
[fs/lustre-release.git] / lustre / lov / lovsub_dev.c
1 // SPDX-License-Identifier: GPL-2.0
2
3 /*
4  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
5  * Use is subject to license terms.
6  *
7  * Copyright (c) 2013, 2015, Intel Corporation.
8  */
9
10 /*
11  * This file is part of Lustre, http://www.lustre.org/
12  *
13  * Implementation of cl_device and cl_device_type for LOVSUB layer.
14  *
15  * Author: Nikita Danilov <nikita.danilov@sun.com>
16  */
17
18 #define DEBUG_SUBSYSTEM S_LOV
19
20 #include "lov_cl_internal.h"
21
22 /** \addtogroup lov
23  *  @{
24  */
25
26 /**
27  * Lov-sub device and device type functions.
28  */
29 static int lovsub_device_init(const struct lu_env *env, struct lu_device *d,
30                               const char *name, struct lu_device *next)
31 {
32         struct lovsub_device  *lsd = lu2lovsub_dev(d);
33         struct lu_device_type *ldt;
34         int rc;
35
36         ENTRY;
37         next->ld_site = d->ld_site;
38         ldt = next->ld_type;
39         LASSERT(ldt != NULL);
40         rc = ldto_device_init(env, next, ldt->ldt_name, NULL);
41         if (rc) {
42                 next->ld_site = NULL;
43                 RETURN(rc);
44         }
45
46         lu_device_get(next);
47         lsd->acid_next = lu2cl_dev(next);
48         RETURN(rc);
49 }
50
51 static struct lu_device *lovsub_device_fini(const struct lu_env *env,
52                                             struct lu_device *d)
53 {
54         struct lu_device *next;
55         struct lovsub_device *lsd;
56
57         ENTRY;
58         lsd = lu2lovsub_dev(d);
59         next = cl2lu_dev(lsd->acid_next);
60         lsd->acid_next = NULL;
61         RETURN(next);
62 }
63
64 static struct lu_device *lovsub_device_free(const struct lu_env *env,
65                                             struct lu_device *d)
66 {
67         struct lovsub_device *lsd = lu2lovsub_dev(d);
68         struct lu_device *next = cl2lu_dev(lsd->acid_next);
69
70         lu_site_print(env, d->ld_site, &d->ld_ref, D_ERROR, lu_cdebug_printer);
71         cl_device_fini(lu2cl_dev(d));
72         OBD_FREE_PTR(lsd);
73         return next;
74 }
75
76 static const struct lu_device_operations lovsub_lu_ops = {
77         .ldo_object_alloc      = lovsub_object_alloc,
78         .ldo_process_config    = NULL,
79         .ldo_recovery_complete = NULL
80 };
81
82 static struct lu_device *lovsub_device_alloc(const struct lu_env *env,
83                                              struct lu_device_type *t,
84                                              struct lustre_cfg *cfg)
85 {
86         struct lu_device *d;
87         struct lovsub_device *lsd;
88
89         OBD_ALLOC_PTR(lsd);
90         if (lsd) {
91                 int result;
92
93                 result = cl_device_init(&lsd->acid_cl, t);
94                 if (result == 0) {
95                         d = lovsub2lu_dev(lsd);
96                         d->ld_ops         = &lovsub_lu_ops;
97                 } else
98                         d = ERR_PTR(result);
99         } else
100                 d = ERR_PTR(-ENOMEM);
101         return d;
102 }
103
104 static const struct lu_device_type_operations lovsub_device_type_ops = {
105         .ldto_device_alloc = lovsub_device_alloc,
106         .ldto_device_free = lovsub_device_free,
107
108         .ldto_device_init = lovsub_device_init,
109         .ldto_device_fini = lovsub_device_fini
110 };
111
112 #define LUSTRE_LOVSUB_NAME         "lovsub"
113
114 struct lu_device_type lovsub_device_type = {
115         .ldt_tags     = LU_DEVICE_CL,
116         .ldt_name     = LUSTRE_LOVSUB_NAME,
117         .ldt_ops      = &lovsub_device_type_ops,
118         .ldt_ctx_tags = LCT_CL_THREAD
119 };
120
121
122 /** @} lov */
123