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 [sun.com URL with a
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 2008 Sun Microsystems, Inc. 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 /* Called with res->lr_lvb_sem held */
58 static int filter_lvbo_init(struct ldlm_resource *res)
60 struct ost_lvb *lvb = NULL;
61 struct obd_device *obd;
62 struct dentry *dentry;
67 LASSERT_SEM_LOCKED(&res->lr_lvb_sem);
72 OBD_ALLOC(lvb, sizeof(*lvb));
76 res->lr_lvb_data = lvb;
77 res->lr_lvb_len = sizeof(*lvb);
79 obd = res->lr_namespace->ns_lvbp;
82 dentry = filter_fid2dentry(obd, NULL, res->lr_name.name[1],
83 res->lr_name.name[0]);
86 CERROR("%s: bad object "LPU64"/"LPU64": rc %d\n", obd->obd_name,
87 res->lr_name.name[0], res->lr_name.name[1], rc);
91 if (dentry->d_inode == NULL)
92 /* This is always true for test_brw */
93 GOTO(out_dentry, rc = -ENOENT);
95 inode_init_lvb(dentry->d_inode, lvb);
97 CDEBUG(D_DLMTRACE, "res: "LPX64" initial lvb size: "LPX64", "
98 "mtime: "LPX64", blocks: "LPX64"\n",
99 res->lr_name.name[0], lvb->lvb_size,
100 lvb->lvb_mtime, lvb->lvb_blocks);
107 OST_LVB_SET_ERR(lvb->lvb_blocks, rc);
108 /* Don't free lvb data on lookup error */
112 /* This will be called in two ways:
114 * m != NULL : called by the DLM itself after a glimpse callback
115 * m == NULL : called by the filter after a disk write
117 * If 'increase_only' is true, don't allow values to move backwards.
119 static int filter_lvbo_update(struct ldlm_resource *res, struct lustre_msg *m,
120 int buf_idx, int increase_only)
124 struct obd_device *obd;
125 struct dentry *dentry;
130 down(&res->lr_lvb_sem);
131 lvb = res->lr_lvb_data;
133 CERROR("No lvb when running lvbo_update!\n");
137 /* Update the LVB from the network message */
141 new = lustre_swab_buf(m, buf_idx, sizeof(*new),
142 lustre_swab_ost_lvb);
144 CERROR("lustre_swab_buf failed\n");
147 if (new->lvb_size > lvb->lvb_size || !increase_only) {
148 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb size: "
149 LPU64" -> "LPU64"\n", res->lr_name.name[0],
150 lvb->lvb_size, new->lvb_size);
151 lvb->lvb_size = new->lvb_size;
153 if (new->lvb_mtime > lvb->lvb_mtime || !increase_only) {
154 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb mtime: "
155 LPU64" -> "LPU64"\n", res->lr_name.name[0],
156 lvb->lvb_mtime, new->lvb_mtime);
157 lvb->lvb_mtime = new->lvb_mtime;
159 if (new->lvb_atime > lvb->lvb_atime || !increase_only) {
160 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb atime: "
161 LPU64" -> "LPU64"\n", res->lr_name.name[0],
162 lvb->lvb_atime, new->lvb_atime);
163 lvb->lvb_atime = new->lvb_atime;
165 if (new->lvb_ctime > lvb->lvb_ctime || !increase_only) {
166 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb ctime: "
167 LPU64" -> "LPU64"\n", res->lr_name.name[0],
168 lvb->lvb_ctime, new->lvb_ctime);
169 lvb->lvb_ctime = new->lvb_ctime;
174 /* Update the LVB from the disk inode */
175 obd = res->lr_namespace->ns_lvbp;
178 dentry = filter_fid2dentry(obd, NULL, res->lr_name.name[1],
179 res->lr_name.name[0]);
181 GOTO(out, rc = PTR_ERR(dentry));
183 if (dentry->d_inode == NULL)
184 GOTO(out_dentry, rc = -ENOENT);
186 if (i_size_read(dentry->d_inode) > lvb->lvb_size || !increase_only) {
187 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb size from disk: "
188 LPU64" -> %llu\n", res->lr_name.name[0],
189 lvb->lvb_size, i_size_read(dentry->d_inode));
190 lvb->lvb_size = i_size_read(dentry->d_inode);
193 if (LTIME_S(dentry->d_inode->i_mtime) >lvb->lvb_mtime|| !increase_only){
194 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb mtime from disk: "
195 LPU64" -> %lu\n", res->lr_name.name[0],
196 lvb->lvb_mtime, LTIME_S(dentry->d_inode->i_mtime));
197 lvb->lvb_mtime = LTIME_S(dentry->d_inode->i_mtime);
199 if (LTIME_S(dentry->d_inode->i_atime) >lvb->lvb_atime|| !increase_only){
200 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb atime from disk: "
201 LPU64" -> %lu\n", res->lr_name.name[0],
202 lvb->lvb_atime, LTIME_S(dentry->d_inode->i_atime));
203 lvb->lvb_atime = LTIME_S(dentry->d_inode->i_atime);
205 if (LTIME_S(dentry->d_inode->i_ctime) >lvb->lvb_ctime|| !increase_only){
206 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb ctime from disk: "
207 LPU64" -> %lu\n", res->lr_name.name[0],
208 lvb->lvb_ctime, LTIME_S(dentry->d_inode->i_ctime));
209 lvb->lvb_ctime = LTIME_S(dentry->d_inode->i_ctime);
211 if (lvb->lvb_blocks != dentry->d_inode->i_blocks) {
212 CDEBUG(D_DLMTRACE,"res: "LPU64" updating lvb blocks from disk: "
213 LPU64" -> %llu\n", res->lr_name.name[0],
214 lvb->lvb_blocks, (unsigned long long)dentry->d_inode->i_blocks);
215 lvb->lvb_blocks = dentry->d_inode->i_blocks;
222 up(&res->lr_lvb_sem);
226 struct ldlm_valblock_ops filter_lvbo = {
227 lvbo_init: filter_lvbo_init,
228 lvbo_update: filter_lvbo_update