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 Lustre, http://www.lustre.org.
13 * Lustre is free software; you can redistribute it and/or
14 * modify it under the terms of version 2 of the GNU General Public
15 * License as published by the Free Software Foundation.
17 * Lustre is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with Lustre; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #define DEBUG_SUBSYSTEM S_FILTER
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/version.h>
33 #include <libcfs/list.h>
34 #include <linux/obd_class.h>
35 #include <linux/lustre_dlm.h>
37 #include "filter_internal.h"
39 /* Called with res->lr_lvb_sem held */
40 static int filter_lvbo_init(struct ldlm_resource *res)
43 struct obdo *oa = NULL;
44 struct ost_lvb *lvb = NULL;
45 struct obd_device *obd;
46 struct dentry *dentry;
50 LASSERT(down_trylock(&res->lr_lvb_sem) != 0);
52 /* we only want lvb's for object resources */
53 /* check for internal locks: these have name[1] != 0 */
54 if (res->lr_name.name[1])
60 OBD_ALLOC(lvb, sizeof(*lvb));
62 GOTO(out, rc = -ENOMEM);
64 res->lr_lvb_data = lvb;
65 res->lr_lvb_len = sizeof(*lvb);
67 obd = res->lr_namespace->ns_lvbp;
72 GOTO(out, rc = -ENOMEM);
74 oa->o_id = res->lr_name.name[0];
75 oa->o_gr = res->lr_name.name[2];
76 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
78 dentry = filter_oa2dentry(obd, oa);
80 GOTO(out, rc = PTR_ERR(dentry));
82 /* Limit the valid bits in the return data to what we actually use */
83 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
84 obdo_from_inode(oa, dentry->d_inode, FILTER_VALID_FLAGS);
87 lvb->lvb_size = dentry->d_inode->i_size;
88 lvb->lvb_mtime = LTIME_S(dentry->d_inode->i_mtime);
89 lvb->lvb_blocks = dentry->d_inode->i_blocks;
91 CDEBUG(D_DLMTRACE, "res: "LPU64" initial lvb size: "LPU64", "
92 "mtime: "LPU64", blocks: "LPU64"\n",
93 res->lr_name.name[0], lvb->lvb_size,
94 lvb->lvb_mtime, lvb->lvb_blocks);
99 /* Don't free lvb data on lookup error */
103 /* This will be called in two ways:
105 * m != NULL : called by the DLM itself after a glimpse callback
106 * m == NULL : called by the filter after a disk write
108 * If 'increase' is true, don't allow values to move backwards.
110 static int filter_lvbo_update(struct ldlm_resource *res, struct lustre_msg *m,
111 int buf_idx, int increase)
114 struct obdo *oa = NULL;
115 struct ost_lvb *lvb = res->lr_lvb_data;
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 if (!res->lr_lvb_data) {
129 CERROR("No lvb when running lvbo_update!\n");
133 /* Update the LVB from the network message */
137 new = lustre_swab_buf(m, buf_idx, sizeof(*new),
138 lustre_swab_ost_lvb);
140 CERROR("lustre_swab_buf failed\n");
141 //GOTO(out, rc = -EPROTO);
144 if (new->lvb_size > lvb->lvb_size || !increase) {
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) {
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) {
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) {
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;
170 /* Update the LVB from the disk inode */
171 obd = res->lr_namespace->ns_lvbp;
176 GOTO(out, rc = -ENOMEM);
178 oa->o_id = res->lr_name.name[0];
179 oa->o_gr = res->lr_name.name[2];
180 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
181 dentry = filter_oa2dentry(obd, oa);
183 GOTO(out, rc = PTR_ERR(dentry));
185 /* Limit the valid bits in the return data to what we actually use */
186 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
187 obdo_from_inode(oa, dentry->d_inode, FILTER_VALID_FLAGS);
189 if (dentry->d_inode->i_size > lvb->lvb_size || !increase) {
190 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb size from disk: "
191 LPU64" -> %llu\n", res->lr_name.name[0],
192 lvb->lvb_size, dentry->d_inode->i_size);
193 lvb->lvb_size = dentry->d_inode->i_size;
196 if (LTIME_S(dentry->d_inode->i_mtime) > lvb->lvb_mtime || !increase) {
197 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb mtime from disk: "
198 LPU64" -> %lu\n", res->lr_name.name[0],
199 lvb->lvb_mtime, LTIME_S(dentry->d_inode->i_mtime));
200 lvb->lvb_mtime = LTIME_S(dentry->d_inode->i_mtime);
202 if (LTIME_S(dentry->d_inode->i_atime) > lvb->lvb_atime || !increase) {
203 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb atime from disk: "
204 LPU64" -> %lu\n", res->lr_name.name[0],
205 lvb->lvb_atime, LTIME_S(dentry->d_inode->i_atime));
206 lvb->lvb_atime = LTIME_S(dentry->d_inode->i_atime);
208 if (LTIME_S(dentry->d_inode->i_ctime) > lvb->lvb_ctime || !increase) {
209 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb ctime from disk: "
210 LPU64" -> %lu\n", res->lr_name.name[0],
211 lvb->lvb_ctime, LTIME_S(dentry->d_inode->i_ctime));
212 lvb->lvb_ctime = LTIME_S(dentry->d_inode->i_ctime);
214 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb blocks from disk: "
215 LPU64" -> %lu\n", res->lr_name.name[0],
216 lvb->lvb_blocks, dentry->d_inode->i_blocks);
217 lvb->lvb_blocks = dentry->d_inode->i_blocks;
223 up(&res->lr_lvb_sem);
227 struct ldlm_valblock_ops filter_lvbo = {
228 lvbo_init: filter_lvbo_init,
229 lvbo_update: filter_lvbo_update