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, 2015, 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 /* Only fill layout if layout lock is granted */
118 if (!ldlm_has_layout(lock) || lock->l_granted_mode != lock->l_req_mode)
121 /* layout lock will be granted to client, fill in lvb with layout */
123 /* XXX create an env to talk to mdt stack. We should get this env from
124 * ptlrpc_thread->t_env. */
125 rc = lu_env_init(&env, LCT_MD_THREAD);
130 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
133 GOTO(out, rc = -ENOMEM);
135 memset(info, 0, sizeof *info);
136 info->mti_env = &env;
137 info->mti_exp = lock->l_export;
140 /* XXX get fid by resource id. why don't include fid in ldlm_resource */
141 fid = &info->mti_tmp_fid2;
142 fid_extract_from_res_name(fid, &lock->l_resource->lr_name);
144 obj = mdt_object_find(&env, info->mti_mdt, fid);
146 GOTO(out, rc = PTR_ERR(obj));
148 if (!mdt_object_exists(obj) || mdt_object_remote(obj))
149 GOTO(out, rc = -ENOENT);
151 child = mdt_object_child(obj);
153 /* get the length of lsm */
154 rc = mo_xattr_get(&env, child, &LU_BUF_NULL, XATTR_NAME_LOV);
159 struct lu_buf *lmm = NULL;
162 CERROR("%s: expected %d actual %d.\n",
163 mdt_obd_name(mdt), rc, lvblen);
164 GOTO(out, rc = -ERANGE);
167 lmm = &info->mti_buf;
171 rc = mo_xattr_get(&env, child, lmm, XATTR_NAME_LOV);
177 if (obj != NULL && !IS_ERR(obj))
178 mdt_object_put(&env, obj);
180 RETURN(rc < 0 ? 0 : rc);
183 static int mdt_lvbo_free(struct ldlm_resource *res)
185 if (IS_LQUOTA_RES(res)) {
186 struct mdt_device *mdt;
188 mdt = ldlm_res_to_ns(res)->ns_lvbp;
189 if (mdt->mdt_qmt_dev == NULL)
192 /* call lvbo free function of quota master */
193 return qmt_hdls.qmth_lvbo_free(mdt->mdt_qmt_dev, res);
199 struct ldlm_valblock_ops mdt_lvbo = {
200 .lvbo_init = mdt_lvbo_init,
201 .lvbo_update = mdt_lvbo_update,
202 .lvbo_size = mdt_lvbo_size,
203 .lvbo_fill = mdt_lvbo_fill,
204 .lvbo_free = mdt_lvbo_free