1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/obdfilter/filter_lvb.c
38 * Author: Peter Braam <braam@clusterfs.com>
39 * Author: Andreas Dilger <adilger@clusterfs.com>
40 * Author: Phil Schwan <phil@clusterfs.com>
43 #define DEBUG_SUBSYSTEM S_FILTER
45 #ifndef AUTOCONF_INCLUDED
46 #include <linux/config.h>
48 #include <linux/module.h>
49 #include <linux/version.h>
51 #include <libcfs/list.h>
52 #include <obd_class.h>
53 #include <lustre_dlm.h>
55 #include "filter_internal.h"
57 static int filter_lvbo_free(struct ldlm_resource *res) {
58 if (res->lr_lvb_inode) {
59 iput(res->lr_lvb_inode);
60 res->lr_lvb_inode = NULL;
64 OBD_FREE(res->lr_lvb_data, res->lr_lvb_len);
69 /* Called with res->lr_lvb_sem held */
70 static int filter_lvbo_init(struct ldlm_resource *res)
72 struct ost_lvb *lvb = NULL;
73 struct obd_device *obd;
74 struct dentry *dentry;
79 LASSERT_SEM_LOCKED(&res->lr_lvb_sem);
84 OBD_ALLOC(lvb, sizeof(*lvb));
88 res->lr_lvb_data = lvb;
89 res->lr_lvb_len = sizeof(*lvb);
91 obd = ldlm_res_to_ns(res)->ns_lvbp;
94 CDEBUG(D_INODE, "%s: filter_lvbo_init(o_seq="LPU64", o_id="
95 LPU64")\n", obd->obd_name, res->lr_name.name[1],
96 res->lr_name.name[0]);
98 dentry = filter_fid2dentry(obd, NULL, res->lr_name.name[1],
99 res->lr_name.name[0]);
100 if (IS_ERR(dentry)) {
101 rc = PTR_ERR(dentry);
102 CERROR("%s: bad object "LPU64"/"LPU64": rc %d\n", obd->obd_name,
103 res->lr_name.name[0], res->lr_name.name[1], rc);
107 if (dentry->d_inode == NULL)
108 /* This is always true for test_brw */
109 GOTO(out_dentry, rc = -ENOENT);
111 inode_init_lvb(dentry->d_inode, lvb);
113 CDEBUG(D_DLMTRACE, "res: "LPX64" initial lvb size: "LPX64", "
114 "mtime: "LPX64", blocks: "LPX64"\n",
115 res->lr_name.name[0], lvb->lvb_size,
116 lvb->lvb_mtime, lvb->lvb_blocks);
118 res->lr_lvb_inode = igrab(dentry->d_inode);
125 OST_LVB_SET_ERR(lvb->lvb_blocks, rc);
126 /* Don't free lvb data on lookup error */
130 /* This will be called in two ways:
132 * r != NULL : called by the DLM itself after a glimpse callback
133 * r == NULL : called by the filter after a disk write
135 * If 'increase_only' is true, don't allow values to move backwards.
137 static int filter_lvbo_update(struct ldlm_resource *res,
138 struct ptlrpc_request *r, int increase_only)
142 struct obd_device *obd;
144 struct inode *tmpinode = NULL;
150 lvb = res->lr_lvb_data;
152 CERROR("No lvb when running lvbo_update!\n");
156 /* Update the LVB from the network message */
160 /* XXX update always from reply buffer */
161 new = req_capsule_server_get(&r->rq_pill, &RMF_DLM_LVB);
164 CERROR("lustre_swab_buf failed\n");
167 if (new->lvb_size > lvb->lvb_size || !increase_only) {
168 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb size: "
169 LPU64" -> "LPU64"\n", res->lr_name.name[0],
170 lvb->lvb_size, new->lvb_size);
171 lvb->lvb_size = new->lvb_size;
173 if (new->lvb_mtime > lvb->lvb_mtime || !increase_only) {
174 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb mtime: "
175 LPU64" -> "LPU64"\n", res->lr_name.name[0],
176 lvb->lvb_mtime, new->lvb_mtime);
177 lvb->lvb_mtime = new->lvb_mtime;
179 if (new->lvb_atime > lvb->lvb_atime || !increase_only) {
180 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb atime: "
181 LPU64" -> "LPU64"\n", res->lr_name.name[0],
182 lvb->lvb_atime, new->lvb_atime);
183 lvb->lvb_atime = new->lvb_atime;
185 if (new->lvb_ctime > lvb->lvb_ctime || !increase_only) {
186 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb ctime: "
187 LPU64" -> "LPU64"\n", res->lr_name.name[0],
188 lvb->lvb_ctime, new->lvb_ctime);
189 lvb->lvb_ctime = new->lvb_ctime;
194 /* Update the LVB from the disk inode */
195 obd = ldlm_res_to_ns(res)->ns_lvbp;
198 inode = res->lr_lvb_inode;
199 /* filter_fid2dentry could fail, esp. in OBD_FAIL_OST_ENOENT test case */
200 if (unlikely(inode == NULL)) {
201 struct dentry *dentry;
205 dentry = filter_fid2dentry(obd, NULL, res->lr_name.name[1],
206 res->lr_name.name[0]);
208 RETURN(PTR_ERR(dentry));
211 tmpinode = igrab(dentry->d_inode);
213 /* tmpinode could be NULL, but it does not matter if other
214 * have set res->lr_lvb_inode */
216 if (res->lr_lvb_inode == NULL) {
217 res->lr_lvb_inode = tmpinode;
220 inode = res->lr_lvb_inode;
223 if (!inode || !inode->i_nlink)
224 GOTO(out, rc = -ENOENT);
226 if (i_size_read(inode) > lvb->lvb_size || !increase_only) {
227 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb size from disk: "
228 LPU64" -> %llu\n", res->lr_name.name[0],
229 lvb->lvb_size, i_size_read(inode));
230 lvb->lvb_size = i_size_read(inode);
233 if (LTIME_S(inode->i_mtime) >lvb->lvb_mtime|| !increase_only){
234 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb mtime from disk: "
235 LPU64" -> %lu\n", res->lr_name.name[0],
236 lvb->lvb_mtime, LTIME_S(inode->i_mtime));
237 lvb->lvb_mtime = LTIME_S(inode->i_mtime);
239 if (LTIME_S(inode->i_atime) >lvb->lvb_atime|| !increase_only){
240 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb atime from disk: "
241 LPU64" -> %lu\n", res->lr_name.name[0],
242 lvb->lvb_atime, LTIME_S(inode->i_atime));
243 lvb->lvb_atime = LTIME_S(inode->i_atime);
245 if (LTIME_S(inode->i_ctime) >lvb->lvb_ctime|| !increase_only){
246 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb ctime from disk: "
247 LPU64" -> %lu\n", res->lr_name.name[0],
248 lvb->lvb_ctime, LTIME_S(inode->i_ctime));
249 lvb->lvb_ctime = LTIME_S(inode->i_ctime);
251 if (lvb->lvb_blocks != inode->i_blocks) {
252 CDEBUG(D_DLMTRACE,"res: "LPU64" updating lvb blocks from disk: "
253 LPU64" -> %llu\n", res->lr_name.name[0],
254 lvb->lvb_blocks, (unsigned long long)inode->i_blocks);
255 lvb->lvb_blocks = inode->i_blocks;
265 struct ldlm_valblock_ops filter_lvbo = {
266 lvbo_init: filter_lvbo_init,
267 lvbo_update: filter_lvbo_update,
268 lvbo_free: filter_lvbo_free