Whamcloud - gitweb
91df890ed84ee589d05d4adccfd98c353e31aa3f
[fs/lustre-release.git] / lustre / mdt / mdt_lvb.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, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 021110-1307, USA
20  *
21  * GPL HEADER END
22  */
23 /*
24  * Copyright (c) 2012, Intel Corporation.
25  * Use is subject to license terms.
26  *
27  * lustre/mdt/mdt_lvb.c
28  *
29  * Author: Jinshan Xiong <jinshan.xiong@intel.com>
30  */
31
32 #define DEBUG_SUBSYSTEM S_MDS
33
34 #include "mdt_internal.h"
35
36 /* Called with res->lr_lvb_sem held */
37 static int mdt_lvbo_init(struct ldlm_resource *res)
38 {
39         if (IS_LQUOTA_RES(res)) {
40                 struct mdt_device       *mdt;
41
42                 mdt = ldlm_res_to_ns(res)->ns_lvbp;
43                 if (mdt->mdt_qmt_dev == NULL)
44                         return 0;
45
46                 /* call lvbo init function of quota master */
47                 return qmt_hdls.qmth_lvbo_init(mdt->mdt_qmt_dev, res);
48         }
49
50         return 0;
51 }
52
53 static int mdt_lvbo_update(struct ldlm_resource *res,
54                            struct ptlrpc_request *req,
55                            int increase_only)
56 {
57         if (IS_LQUOTA_RES(res)) {
58                 struct mdt_device       *mdt;
59
60                 mdt = ldlm_res_to_ns(res)->ns_lvbp;
61                 if (mdt->mdt_qmt_dev == NULL)
62                         return 0;
63
64                 /* call lvbo update function of quota master */
65                 return qmt_hdls.qmth_lvbo_update(mdt->mdt_qmt_dev, res, req,
66                                                  increase_only);
67         }
68
69         return 0;
70 }
71
72
73 static int mdt_lvbo_size(struct ldlm_lock *lock)
74 {
75         if (IS_LQUOTA_RES(lock->l_resource)) {
76                 struct mdt_device       *mdt;
77
78                 mdt = ldlm_res_to_ns(lock->l_resource)->ns_lvbp;
79                 if (mdt->mdt_qmt_dev == NULL)
80                         return 0;
81
82                 /* call lvbo size function of quota master */
83                 return qmt_hdls.qmth_lvbo_size(mdt->mdt_qmt_dev, lock);
84         }
85
86         return 0;
87 }
88
89 static int mdt_lvbo_fill(struct ldlm_lock *lock, void *lvb, int lvblen)
90 {
91         if (IS_LQUOTA_RES(lock->l_resource)) {
92                 struct mdt_device       *mdt;
93
94                 mdt = ldlm_res_to_ns(lock->l_resource)->ns_lvbp;
95                 if (mdt->mdt_qmt_dev == NULL)
96                         return 0;
97
98                 /* call lvbo fill function of quota master */
99                 return qmt_hdls.qmth_lvbo_fill(mdt->mdt_qmt_dev, lock, lvb,
100                                                lvblen);
101         }
102
103         return 0;
104 }
105
106 static int mdt_lvbo_free(struct ldlm_resource *res)
107 {
108         if (IS_LQUOTA_RES(res)) {
109                 struct mdt_device       *mdt;
110
111                 mdt = ldlm_res_to_ns(res)->ns_lvbp;
112                 if (mdt->mdt_qmt_dev == NULL)
113                         return 0;
114
115                 /* call lvbo free function of quota master */
116                 return qmt_hdls.qmth_lvbo_free(mdt->mdt_qmt_dev, res);
117         }
118
119         return 0;
120 }
121
122 struct ldlm_valblock_ops mdt_lvbo = {
123         lvbo_init:      mdt_lvbo_init,
124         lvbo_update:    mdt_lvbo_update,
125         lvbo_size:      mdt_lvbo_size,
126         lvbo_fill:      mdt_lvbo_fill,
127         lvbo_free:      mdt_lvbo_free
128 };