1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * linux/fs/obdfilter/filter_log.c
6 * Copyright (c) 2001-2003 Cluster File Systems, Inc.
7 * Author: Peter Braam <braam@clusterfs.com>
8 * Author: Andreas Dilger <adilger@clusterfs.com>
9 * Author: Phil Schwan <phil@clusterfs.com>
11 * This file is part of the Lustre file system, http://www.lustre.org
12 * Lustre is a trademark of Cluster File Systems, Inc.
14 * You may have signed or agreed to another license before downloading
15 * this software. If so, you are bound by the terms and conditions
16 * of that agreement, and the following does not apply to you. See the
17 * LICENSE file included with this distribution for more information.
19 * If you did not agree to a different license, then this copy of Lustre
20 * is open source software; you can redistribute it and/or modify it
21 * under the terms of version 2 of the GNU General Public License as
22 * published by the Free Software Foundation.
24 * In either case, Lustre is distributed in the hope that it will be
25 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
26 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * license text for more details.
30 #define DEBUG_SUBSYSTEM S_FILTER
32 #ifndef AUTOCONF_INCLUDED
33 #include <linux/config.h>
35 #include <linux/module.h>
36 #include <linux/version.h>
38 #include <libcfs/list.h>
39 #include <obd_class.h>
40 #include <lustre_dlm.h>
42 #include "filter_internal.h"
44 /* Called with res->lr_lvb_sem held */
45 static int filter_lvbo_init(struct ldlm_resource *res)
47 struct ost_lvb *lvb = NULL;
48 struct obd_device *obd;
49 struct dentry *dentry;
54 LASSERT_SEM_LOCKED(&res->lr_lvb_sem);
56 /* we only want lvb's for object resources */
57 /* check for internal locks: these have name[1] != 0 */
58 if (res->lr_name.name[1])
64 OBD_ALLOC(lvb, sizeof(*lvb));
68 res->lr_lvb_data = lvb;
69 res->lr_lvb_len = sizeof(*lvb);
71 obd = res->lr_namespace->ns_lvbp;
74 dentry = filter_fid2dentry(obd, NULL, res->lr_name.name[2],
75 res->lr_name.name[0]);
78 CERROR("%s: bad object "LPU64"/"LPU64": rc %d\n", obd->obd_name,
79 res->lr_name.name[0], res->lr_name.name[1], rc);
83 if (dentry->d_inode == NULL)
84 /* This is always true for test_brw */
85 GOTO(out_dentry, rc = -ENOENT);
87 inode_init_lvb(dentry->d_inode, lvb);
89 CDEBUG(D_DLMTRACE, "res: "LPX64" initial lvb size: "LPX64", "
90 "mtime: "LPX64", blocks: "LPX64"\n",
91 res->lr_name.name[0], lvb->lvb_size,
92 lvb->lvb_mtime, lvb->lvb_blocks);
99 OST_LVB_SET_ERR(lvb->lvb_blocks, rc);
100 /* Don't free lvb data on lookup error */
104 /* This will be called in two ways:
106 * m != NULL : called by the DLM itself after a glimpse callback
107 * m == NULL : called by the filter after a disk write
109 * If 'increase_only' is true, don't allow values to move backwards.
111 static int filter_lvbo_update(struct ldlm_resource *res, struct lustre_msg *m,
112 int buf_idx, int increase_only)
116 struct obd_device *obd;
117 struct dentry *dentry;
122 /* we only want lvb's for object resources */
123 /* check for internal locks: these have name[1] != 0 */
124 if (res->lr_name.name[1])
127 down(&res->lr_lvb_sem);
128 lvb = res->lr_lvb_data;
130 CERROR("No lvb when running lvbo_update!\n");
134 /* Update the LVB from the network message */
138 new = lustre_swab_buf(m, buf_idx, sizeof(*new),
139 lustre_swab_ost_lvb);
141 CERROR("lustre_swab_buf failed\n");
144 if (new->lvb_size > lvb->lvb_size || !increase_only) {
145 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb size: "
146 LPU64" -> "LPU64"\n", res->lr_name.name[0],
147 lvb->lvb_size, new->lvb_size);
148 lvb->lvb_size = new->lvb_size;
150 if (new->lvb_mtime > lvb->lvb_mtime || !increase_only) {
151 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb mtime: "
152 LPU64" -> "LPU64"\n", res->lr_name.name[0],
153 lvb->lvb_mtime, new->lvb_mtime);
154 lvb->lvb_mtime = new->lvb_mtime;
156 if (new->lvb_atime > lvb->lvb_atime || !increase_only) {
157 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb atime: "
158 LPU64" -> "LPU64"\n", res->lr_name.name[0],
159 lvb->lvb_atime, new->lvb_atime);
160 lvb->lvb_atime = new->lvb_atime;
162 if (new->lvb_ctime > lvb->lvb_ctime || !increase_only) {
163 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb ctime: "
164 LPU64" -> "LPU64"\n", res->lr_name.name[0],
165 lvb->lvb_ctime, new->lvb_ctime);
166 lvb->lvb_ctime = new->lvb_ctime;
171 /* Update the LVB from the disk inode */
172 obd = res->lr_namespace->ns_lvbp;
175 dentry = filter_fid2dentry(obd, NULL, res->lr_name.name[2],
176 res->lr_name.name[0]);
178 GOTO(out, rc = PTR_ERR(dentry));
180 if (dentry->d_inode == NULL)
181 GOTO(out_dentry, rc = -ENOENT);
183 if (i_size_read(dentry->d_inode) > lvb->lvb_size || !increase_only) {
184 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb size from disk: "
185 LPU64" -> %llu\n", res->lr_name.name[0],
186 lvb->lvb_size, i_size_read(dentry->d_inode));
187 lvb->lvb_size = i_size_read(dentry->d_inode);
190 if (LTIME_S(dentry->d_inode->i_mtime) >lvb->lvb_mtime|| !increase_only){
191 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb mtime from disk: "
192 LPU64" -> %lu\n", res->lr_name.name[0],
193 lvb->lvb_mtime, LTIME_S(dentry->d_inode->i_mtime));
194 lvb->lvb_mtime = LTIME_S(dentry->d_inode->i_mtime);
196 if (LTIME_S(dentry->d_inode->i_atime) >lvb->lvb_atime|| !increase_only){
197 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb atime from disk: "
198 LPU64" -> %lu\n", res->lr_name.name[0],
199 lvb->lvb_atime, LTIME_S(dentry->d_inode->i_atime));
200 lvb->lvb_atime = LTIME_S(dentry->d_inode->i_atime);
202 if (LTIME_S(dentry->d_inode->i_ctime) >lvb->lvb_ctime|| !increase_only){
203 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb ctime from disk: "
204 LPU64" -> %lu\n", res->lr_name.name[0],
205 lvb->lvb_ctime, LTIME_S(dentry->d_inode->i_ctime));
206 lvb->lvb_ctime = LTIME_S(dentry->d_inode->i_ctime);
208 if (lvb->lvb_blocks != dentry->d_inode->i_blocks) {
209 CDEBUG(D_DLMTRACE,"res: "LPU64" updating lvb blocks from disk: "
210 LPU64" -> %llu\n", res->lr_name.name[0],
211 lvb->lvb_blocks, (unsigned long long)dentry->d_inode->i_blocks);
212 lvb->lvb_blocks = dentry->d_inode->i_blocks;
219 up(&res->lr_lvb_sem);
223 struct ldlm_valblock_ops filter_lvbo = {
224 lvbo_init: filter_lvbo_init,
225 lvbo_update: filter_lvbo_update