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, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 021110-1307, USA
24 * Copyright (c) 2012, 2013, Intel Corporation.
25 * Use is subject to license terms.
27 * lustre/mdt/mdt_lvb.c
29 * Author: Jinshan Xiong <jinshan.xiong@intel.com>
32 #define DEBUG_SUBSYSTEM S_MDS
34 #include "mdt_internal.h"
36 /* Called with res->lr_lvb_sem held */
37 static int mdt_lvbo_init(struct ldlm_resource *res)
39 if (IS_LQUOTA_RES(res)) {
40 struct mdt_device *mdt;
42 mdt = ldlm_res_to_ns(res)->ns_lvbp;
43 if (mdt->mdt_qmt_dev == NULL)
46 /* call lvbo init function of quota master */
47 return qmt_hdls.qmth_lvbo_init(mdt->mdt_qmt_dev, res);
53 static int mdt_lvbo_update(struct ldlm_resource *res,
54 struct ptlrpc_request *req,
57 if (IS_LQUOTA_RES(res)) {
58 struct mdt_device *mdt;
60 mdt = ldlm_res_to_ns(res)->ns_lvbp;
61 if (mdt->mdt_qmt_dev == NULL)
64 /* call lvbo update function of quota master */
65 return qmt_hdls.qmth_lvbo_update(mdt->mdt_qmt_dev, res, req,
73 static int mdt_lvbo_size(struct ldlm_lock *lock)
75 struct mdt_device *mdt;
77 /* resource on server side never changes. */
78 mdt = ldlm_res_to_ns(lock->l_resource)->ns_lvbp;
81 if (IS_LQUOTA_RES(lock->l_resource)) {
82 if (mdt->mdt_qmt_dev == NULL)
85 /* call lvbo size function of quota master */
86 return qmt_hdls.qmth_lvbo_size(mdt->mdt_qmt_dev, lock);
89 if (ldlm_has_layout(lock))
90 return mdt->mdt_max_mdsize;
95 static int mdt_lvbo_fill(struct ldlm_lock *lock, void *lvb, int lvblen)
98 struct mdt_thread_info *info;
99 struct mdt_device *mdt;
101 struct mdt_object *obj = NULL;
102 struct md_object *child = NULL;
106 mdt = ldlm_lock_to_ns(lock)->ns_lvbp;
107 if (IS_LQUOTA_RES(lock->l_resource)) {
108 if (mdt->mdt_qmt_dev == NULL)
111 /* call lvbo fill function of quota master */
112 rc = qmt_hdls.qmth_lvbo_fill(mdt->mdt_qmt_dev, lock, lvb,
117 if (!ldlm_has_layout(lock))
120 /* layout lock will be granted to client, fill in lvb with layout */
122 /* XXX create an env to talk to mdt stack. We should get this env from
123 * ptlrpc_thread->t_env. */
124 rc = lu_env_init(&env, LCT_MD_THREAD);
129 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
132 GOTO(out, rc = -ENOMEM);
134 memset(info, 0, sizeof *info);
135 info->mti_env = &env;
136 info->mti_exp = lock->l_export;
139 /* XXX get fid by resource id. why don't include fid in ldlm_resource */
140 fid = &info->mti_tmp_fid2;
141 fid_extract_from_res_name(fid, &lock->l_resource->lr_name);
143 obj = mdt_object_find(&env, info->mti_mdt, fid);
145 GOTO(out, rc = PTR_ERR(obj));
147 if (!mdt_object_exists(obj) || mdt_object_remote(obj))
148 GOTO(out, rc = -ENOENT);
150 child = mdt_object_child(obj);
152 /* get the length of lsm */
153 rc = mo_xattr_get(&env, child, &LU_BUF_NULL, XATTR_NAME_LOV);
158 struct lu_buf *lmm = NULL;
161 CERROR("%s: expected %d actual %d.\n",
162 mdt_obd_name(mdt), rc, lvblen);
163 GOTO(out, rc = -ERANGE);
166 lmm = &info->mti_buf;
170 rc = mo_xattr_get(&env, child, lmm, XATTR_NAME_LOV);
176 if (obj != NULL && !IS_ERR(obj))
177 mdt_object_put(&env, obj);
179 RETURN(rc < 0 ? 0 : rc);
182 static int mdt_lvbo_free(struct ldlm_resource *res)
184 if (IS_LQUOTA_RES(res)) {
185 struct mdt_device *mdt;
187 mdt = ldlm_res_to_ns(res)->ns_lvbp;
188 if (mdt->mdt_qmt_dev == NULL)
191 /* call lvbo free function of quota master */
192 return qmt_hdls.qmth_lvbo_free(mdt->mdt_qmt_dev, res);
198 struct ldlm_valblock_ops mdt_lvbo = {
199 lvbo_init: mdt_lvbo_init,
200 lvbo_update: mdt_lvbo_update,
201 lvbo_size: mdt_lvbo_size,
202 lvbo_fill: mdt_lvbo_fill,
203 lvbo_free: mdt_lvbo_free