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, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/ofd/ofd_lvb.c
38 * Author: Mikhail Pershin <tappro@whamcloud.com>
39 * Author: Alexey Zhuravlev <bzzz@whamcloud.com>
42 #define DEBUG_SUBSYSTEM S_FILTER
44 #include "ofd_internal.h"
46 static int ofd_lvbo_free(struct ldlm_resource *res)
49 OBD_FREE(res->lr_lvb_data, res->lr_lvb_len);
54 /* Called with res->lr_lvb_sem held */
55 static int ofd_lvbo_init(struct ldlm_resource *res)
58 struct ofd_device *ofd;
59 struct ofd_object *fo;
60 struct ofd_thread_info *info;
67 LASSERT(mutex_is_locked(&res->lr_lvb_mutex));
69 if (res->lr_lvb_data != NULL)
72 ofd = ldlm_res_to_ns(res)->ns_lvbp;
75 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_OST_LVB))
78 rc = lu_env_init(&env, LCT_DT_THREAD);
84 GOTO(out_env, rc = -ENOMEM);
86 res->lr_lvb_data = lvb;
87 res->lr_lvb_len = sizeof(*lvb);
89 info = ofd_info_init(&env, NULL);
90 ost_fid_from_resid(&info->fti_fid, &res->lr_name);
91 fo = ofd_object_find(&env, ofd, &info->fti_fid);
93 GOTO(out_lvb, rc = PTR_ERR(fo));
95 rc = ofd_attr_get(&env, fo, &info->fti_attr);
99 lvb->lvb_size = info->fti_attr.la_size;
100 lvb->lvb_blocks = info->fti_attr.la_blocks;
101 lvb->lvb_mtime = info->fti_attr.la_mtime;
102 lvb->lvb_atime = info->fti_attr.la_atime;
103 lvb->lvb_ctime = info->fti_attr.la_ctime;
105 CDEBUG(D_DLMTRACE, "res: "DFID" initial lvb size: "LPU64", "
106 "mtime: "LPX64", blocks: "LPX64"\n",
107 PFID(&info->fti_fid), lvb->lvb_size,
108 lvb->lvb_mtime, lvb->lvb_blocks);
112 ofd_object_put(&env, fo);
115 OST_LVB_SET_ERR(lvb->lvb_blocks, rc);
118 /* Don't free lvb data on lookup error */
122 /* This will be called in two ways:
124 * r != NULL : called by the DLM itself after a glimpse callback
125 * r == NULL : called by the ofd after a disk write
127 * If 'increase_only' is true, don't allow values to move backwards.
129 static int ofd_lvbo_update(struct ldlm_resource *res,
130 struct ptlrpc_request *req, int increase_only)
132 struct ofd_device *ofd;
133 struct ofd_object *fo;
134 struct ofd_thread_info *info;
141 LASSERT(res != NULL);
143 ofd = ldlm_res_to_ns(res)->ns_lvbp;
144 LASSERT(ofd != NULL);
146 rc = lu_env_init(&env, LCT_DT_THREAD);
150 info = ofd_info_init(&env, NULL);
151 fid_extract_from_res_name(&info->fti_fid, &res->lr_name);
153 lvb = res->lr_lvb_data;
155 CERROR("%s: no LVB data for "DFID"\n",
156 ofd_obd(ofd)->obd_name, PFID(&info->fti_fid));
157 GOTO(out_env, rc = 0);
160 /* Update the LVB from the network message */
162 struct ost_lvb *rpc_lvb;
165 if (req->rq_import != NULL)
166 lvb_type = imp_connect_lvb_type(req->rq_import);
168 lvb_type = exp_connect_lvb_type(req->rq_export);
171 struct ost_lvb_v1 *lvb_v1;
173 lvb_v1 = req_capsule_server_swab_get(&req->rq_pill,
174 &RMF_DLM_LVB, lustre_swab_ost_lvb_v1);
178 rpc_lvb = &info->fti_lvb;
179 memcpy(rpc_lvb, lvb_v1, sizeof *lvb_v1);
180 rpc_lvb->lvb_mtime_ns = 0;
181 rpc_lvb->lvb_atime_ns = 0;
182 rpc_lvb->lvb_ctime_ns = 0;
184 rpc_lvb = req_capsule_server_swab_get(&req->rq_pill,
186 lustre_swab_ost_lvb);
192 if (rpc_lvb->lvb_size > lvb->lvb_size || !increase_only) {
193 CDEBUG(D_DLMTRACE, "res: "DFID" updating lvb size: "
194 LPU64" -> "LPU64"\n", PFID(&info->fti_fid),
195 lvb->lvb_size, rpc_lvb->lvb_size);
196 lvb->lvb_size = rpc_lvb->lvb_size;
198 if (rpc_lvb->lvb_mtime > lvb->lvb_mtime || !increase_only) {
199 CDEBUG(D_DLMTRACE, "res: "DFID" updating lvb mtime: "
200 LPU64" -> "LPU64"\n", PFID(&info->fti_fid),
201 lvb->lvb_mtime, rpc_lvb->lvb_mtime);
202 lvb->lvb_mtime = rpc_lvb->lvb_mtime;
204 if (rpc_lvb->lvb_atime > lvb->lvb_atime || !increase_only) {
205 CDEBUG(D_DLMTRACE, "res: "DFID" updating lvb atime: "
206 LPU64" -> "LPU64"\n", PFID(&info->fti_fid),
207 lvb->lvb_atime, rpc_lvb->lvb_atime);
208 lvb->lvb_atime = rpc_lvb->lvb_atime;
210 if (rpc_lvb->lvb_ctime > lvb->lvb_ctime || !increase_only) {
211 CDEBUG(D_DLMTRACE, "res: "DFID" updating lvb ctime: "
212 LPU64" -> "LPU64"\n", PFID(&info->fti_fid),
213 lvb->lvb_ctime, rpc_lvb->lvb_ctime);
214 lvb->lvb_ctime = rpc_lvb->lvb_ctime;
216 if (rpc_lvb->lvb_blocks > lvb->lvb_blocks || !increase_only) {
217 CDEBUG(D_DLMTRACE, "res: "DFID" updating lvb blocks: "
218 LPU64" -> "LPU64"\n", PFID(&info->fti_fid),
219 lvb->lvb_blocks, rpc_lvb->lvb_blocks);
220 lvb->lvb_blocks = rpc_lvb->lvb_blocks;
226 /* Update the LVB from the disk inode */
227 ost_fid_from_resid(&info->fti_fid, &res->lr_name);
228 fo = ofd_object_find(&env, ofd, &info->fti_fid);
230 GOTO(out_env, rc = PTR_ERR(fo));
232 rc = ofd_attr_get(&env, fo, &info->fti_attr);
237 if (info->fti_attr.la_size > lvb->lvb_size || !increase_only) {
238 CDEBUG(D_DLMTRACE, "res: "DFID" updating lvb size from disk: "
239 LPU64" -> %llu\n", PFID(&info->fti_fid),
240 lvb->lvb_size, info->fti_attr.la_size);
241 lvb->lvb_size = info->fti_attr.la_size;
244 if (info->fti_attr.la_mtime >lvb->lvb_mtime || !increase_only) {
245 CDEBUG(D_DLMTRACE, "res: "DFID" updating lvb mtime from disk: "
246 LPU64" -> "LPU64"\n", PFID(&info->fti_fid),
247 lvb->lvb_mtime, info->fti_attr.la_mtime);
248 lvb->lvb_mtime = info->fti_attr.la_mtime;
250 if (info->fti_attr.la_atime >lvb->lvb_atime || !increase_only) {
251 CDEBUG(D_DLMTRACE, "res: "DFID" updating lvb atime from disk: "
252 LPU64" -> "LPU64"\n", PFID(&info->fti_fid),
253 lvb->lvb_atime, info->fti_attr.la_atime);
254 lvb->lvb_atime = info->fti_attr.la_atime;
256 if (info->fti_attr.la_ctime >lvb->lvb_ctime || !increase_only) {
257 CDEBUG(D_DLMTRACE, "res: "DFID" updating lvb ctime from disk: "
258 LPU64" -> "LPU64"\n", PFID(&info->fti_fid),
259 lvb->lvb_ctime, info->fti_attr.la_ctime);
260 lvb->lvb_ctime = info->fti_attr.la_ctime;
262 if (info->fti_attr.la_blocks > lvb->lvb_blocks || !increase_only) {
263 CDEBUG(D_DLMTRACE, "res: "DFID" updating lvb blocks from disk: "
264 LPU64" -> %llu\n", PFID(&info->fti_fid), lvb->lvb_blocks,
265 (unsigned long long)info->fti_attr.la_blocks);
266 lvb->lvb_blocks = info->fti_attr.la_blocks;
271 ofd_object_put(&env, fo);
277 static int ofd_lvbo_size(struct ldlm_lock *lock)
279 if (lock->l_export != NULL && exp_connect_lvb_type(lock->l_export))
280 return sizeof(struct ost_lvb);
282 return sizeof(struct ost_lvb_v1);
285 static int ofd_lvbo_fill(struct ldlm_lock *lock, void *buf, int buflen)
287 struct ldlm_resource *res = lock->l_resource;
290 /* Former lvbo_init not allocate the "LVB". */
291 if (unlikely(res->lr_lvb_len == 0))
294 lvb_len = ofd_lvbo_size(lock);
295 LASSERT(lvb_len <= res->lr_lvb_len);
297 if (lvb_len > buflen)
301 memcpy(buf, res->lr_lvb_data, lvb_len);
307 struct ldlm_valblock_ops ofd_lvbo = {
308 .lvbo_init = ofd_lvbo_init,
309 .lvbo_update = ofd_lvbo_update,
310 .lvbo_free = ofd_lvbo_free,
311 .lvbo_size = ofd_lvbo_size,
312 .lvbo_fill = ofd_lvbo_fill