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) 2011, 2012, Whamcloud, Inc.
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)
57 struct ost_lvb *lvb = NULL;
58 struct ofd_device *ofd;
59 struct ofd_object *fo;
60 struct ofd_thread_info *info;
67 LASSERT_MUTEX_LOCKED(&res->lr_lvb_mutex);
69 if (res->lr_lvb_data != NULL)
72 ofd = ldlm_res_to_ns(res)->ns_lvbp;
75 rc = lu_env_init(&env, LCT_DT_THREAD);
83 res->lr_lvb_data = lvb;
84 res->lr_lvb_len = sizeof(*lvb);
86 info = ofd_info_init(&env, NULL);
87 ofd_fid_from_resid(&info->fti_fid, &res->lr_name);
88 fo = ofd_object_find(&env, ofd, &info->fti_fid);
90 GOTO(out, rc = PTR_ERR(fo));
92 rc = ofd_attr_get(&env, fo, &info->fti_attr);
96 lvb->lvb_size = info->fti_attr.la_size;
97 lvb->lvb_blocks = info->fti_attr.la_blocks;
98 lvb->lvb_mtime = info->fti_attr.la_mtime;
99 lvb->lvb_atime = info->fti_attr.la_atime;
100 lvb->lvb_ctime = info->fti_attr.la_ctime;
102 CDEBUG(D_DLMTRACE, "res: "LPX64" initial lvb size: "LPX64", "
103 "mtime: "LPX64", blocks: "LPX64"\n",
104 res->lr_name.name[0], lvb->lvb_size,
105 lvb->lvb_mtime, lvb->lvb_blocks);
109 ofd_object_put(&env, fo);
113 OST_LVB_SET_ERR(lvb->lvb_blocks, rc);
114 /* Don't free lvb data on lookup error */
118 /* This will be called in two ways:
120 * r != NULL : called by the DLM itself after a glimpse callback
121 * r == NULL : called by the ofd after a disk write
123 * If 'increase_only' is true, don't allow values to move backwards.
125 static int ofd_lvbo_update(struct ldlm_resource *res,
126 struct ptlrpc_request *req, int increase_only)
128 struct ofd_device *ofd;
129 struct ofd_object *fo;
130 struct ofd_thread_info *info;
137 LASSERT(res != NULL);
139 ofd = ldlm_res_to_ns(res)->ns_lvbp;
140 LASSERT(ofd != NULL);
142 lvb = res->lr_lvb_data;
144 CERROR("%s: no lvb when running lvbo_update, res: "LPU64"!\n",
145 ofd_obd(ofd)->obd_name, res->lr_name.name[0]);
149 rc = lu_env_init(&env, LCT_DT_THREAD);
151 GOTO(out_unlock, rc);
153 info = ofd_info_init(&env, NULL);
154 /* Update the LVB from the network message */
156 struct ost_lvb *rpc_lvb;
158 /* XXX update always from reply buffer */
159 rpc_lvb = req_capsule_server_get(&req->rq_pill, &RMF_DLM_LVB);
160 if (rpc_lvb == NULL) {
161 CERROR("lustre_swab_buf failed\n");
165 if (rpc_lvb->lvb_size > lvb->lvb_size || !increase_only) {
166 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb size: "
167 LPU64" -> "LPU64"\n", res->lr_name.name[0],
168 lvb->lvb_size, rpc_lvb->lvb_size);
169 lvb->lvb_size = rpc_lvb->lvb_size;
171 if (rpc_lvb->lvb_mtime > lvb->lvb_mtime || !increase_only) {
172 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb mtime: "
173 LPU64" -> "LPU64"\n", res->lr_name.name[0],
174 lvb->lvb_mtime, rpc_lvb->lvb_mtime);
175 lvb->lvb_mtime = rpc_lvb->lvb_mtime;
177 if (rpc_lvb->lvb_atime > lvb->lvb_atime || !increase_only) {
178 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb atime: "
179 LPU64" -> "LPU64"\n", res->lr_name.name[0],
180 lvb->lvb_atime, rpc_lvb->lvb_atime);
181 lvb->lvb_atime = rpc_lvb->lvb_atime;
183 if (rpc_lvb->lvb_ctime > lvb->lvb_ctime || !increase_only) {
184 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb ctime: "
185 LPU64" -> "LPU64"\n", res->lr_name.name[0],
186 lvb->lvb_ctime, rpc_lvb->lvb_ctime);
187 lvb->lvb_ctime = rpc_lvb->lvb_ctime;
193 /* Update the LVB from the disk inode */
194 ofd_fid_from_resid(&info->fti_fid, &res->lr_name);
195 fo = ofd_object_find(&env, ofd, &info->fti_fid);
197 GOTO(out_env, rc = PTR_ERR(fo));
199 rc = ofd_attr_get(&env, fo, &info->fti_attr);
204 if (info->fti_attr.la_size > lvb->lvb_size || !increase_only) {
205 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb size from disk: "
206 LPU64" -> %llu\n", res->lr_name.name[0],
207 lvb->lvb_size, info->fti_attr.la_size);
208 lvb->lvb_size = info->fti_attr.la_size;
211 if (info->fti_attr.la_mtime >lvb->lvb_mtime || !increase_only) {
212 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb mtime from disk: "
213 LPU64" -> "LPU64"\n", res->lr_name.name[0],
214 lvb->lvb_mtime, info->fti_attr.la_mtime);
215 lvb->lvb_mtime = info->fti_attr.la_mtime;
217 if (info->fti_attr.la_atime >lvb->lvb_atime || !increase_only) {
218 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb atime from disk: "
219 LPU64" -> "LPU64"\n", res->lr_name.name[0],
220 lvb->lvb_atime, info->fti_attr.la_atime);
221 lvb->lvb_atime = info->fti_attr.la_atime;
223 if (info->fti_attr.la_ctime >lvb->lvb_ctime || !increase_only) {
224 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb ctime from disk: "
225 LPU64" -> "LPU64"\n", res->lr_name.name[0],
226 lvb->lvb_ctime, info->fti_attr.la_ctime);
227 lvb->lvb_ctime = info->fti_attr.la_ctime;
229 if (lvb->lvb_blocks != info->fti_attr.la_blocks) {
230 CDEBUG(D_DLMTRACE,"res: "LPU64" updating lvb blocks from disk: "
231 LPU64" -> %llu\n", res->lr_name.name[0],
233 (unsigned long long)info->fti_attr.la_blocks);
234 lvb->lvb_blocks = info->fti_attr.la_blocks;
239 ofd_object_put(&env, fo);
246 struct ldlm_valblock_ops ofd_lvbo = {
247 lvbo_init: ofd_lvbo_init,
248 lvbo_update: ofd_lvbo_update,
249 lvbo_free: ofd_lvbo_free,