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 <portals/list.h>
34 #include <linux/obd_class.h>
35 #include <linux/lustre_dlm.h>
37 #include "filter_internal.h"
39 static int filter_lvbo_init(struct ldlm_resource *res)
42 struct ost_lvb *lvb = NULL;
43 struct obd_device *obd;
44 struct dentry *dentry;
49 /* we only want lvb's for object resources */
50 /* check for internal locks: these have name[1] != 0 */
51 if (res->lr_name.name[1])
54 down(&res->lr_lvb_sem);
58 OBD_ALLOC(lvb, sizeof(*lvb));
60 GOTO(out, rc = -ENOMEM);
62 res->lr_lvb_data = lvb;
63 res->lr_lvb_len = sizeof(*lvb);
65 obd = res->lr_namespace->ns_lvbp;
68 dentry = filter_fid2dentry(obd, NULL, 0, res->lr_name.name[0]);
70 GOTO(out, rc = PTR_ERR(dentry));
72 if (dentry->d_inode == NULL)
73 GOTO(out, rc = -ENOENT);
75 lvb->lvb_size = dentry->d_inode->i_size;
76 lvb->lvb_mtime = LTIME_S(dentry->d_inode->i_mtime);
77 lvb->lvb_blocks = dentry->d_inode->i_blocks;
79 CDEBUG(D_DLMTRACE, "res: "LPU64" initial lvb size: "LPU64", "
80 "mtime: "LPU64", blocks: "LPU64"\n",
81 res->lr_name.name[0], lvb->lvb_size,
82 lvb->lvb_mtime, lvb->lvb_blocks);
85 /* Don't free lvb data on lookup error */
90 /* This will be called in two ways:
92 * m != NULL : called by the DLM itself after a glimpse callback
93 * m == NULL : called by the filter after a disk write
95 * If 'increase' is true, don't allow values to move backwards.
97 static int filter_lvbo_update(struct ldlm_resource *res, struct lustre_msg *m,
98 int buf_idx, int increase)
101 struct ost_lvb *lvb = res->lr_lvb_data;
102 struct obd_device *obd;
103 struct dentry *dentry;
108 /* we only want lvb's for object resources */
109 /* check for internal locks: these have name[1] != 0 */
110 if (res->lr_name.name[1])
113 down(&res->lr_lvb_sem);
114 if (!res->lr_lvb_data) {
115 CERROR("No lvb when running lvbo_update!\n");
119 /* Update the LVB from the network message */
123 new = lustre_swab_buf(m, buf_idx, sizeof(*new),
124 lustre_swab_ost_lvb);
126 CERROR("lustre_swab_buf failed\n");
127 //GOTO(out, rc = -EPROTO);
130 if (new->lvb_size > lvb->lvb_size || !increase) {
131 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb size: "
132 LPU64" -> "LPU64"\n", res->lr_name.name[0],
133 lvb->lvb_size, new->lvb_size);
134 lvb->lvb_size = new->lvb_size;
136 if (new->lvb_mtime > lvb->lvb_mtime || !increase) {
137 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb mtime: "
138 LPU64" -> "LPU64"\n", res->lr_name.name[0],
139 lvb->lvb_mtime, new->lvb_mtime);
140 lvb->lvb_mtime = new->lvb_mtime;
142 if (new->lvb_blocks > lvb->lvb_blocks || !increase) {
143 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb blocks: "
144 LPU64" -> "LPU64"\n", res->lr_name.name[0],
145 lvb->lvb_blocks, new->lvb_blocks);
146 lvb->lvb_blocks = new->lvb_blocks;
151 /* Update the LVB from the disk inode */
152 obd = res->lr_namespace->ns_lvbp;
155 dentry = filter_fid2dentry(obd, NULL, 0, res->lr_name.name[0]);
157 GOTO(out, rc = PTR_ERR(dentry));
159 if (dentry->d_inode->i_size > lvb->lvb_size || !increase) {
160 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb size from disk: "
161 LPU64" -> %llu\n", res->lr_name.name[0],
162 lvb->lvb_size, dentry->d_inode->i_size);
163 lvb->lvb_size = dentry->d_inode->i_size;
166 if (LTIME_S(dentry->d_inode->i_mtime) > lvb->lvb_mtime || !increase) {
167 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb mtime from disk: "
168 LPU64" -> %lu\n", res->lr_name.name[0],
169 lvb->lvb_mtime, LTIME_S(dentry->d_inode->i_mtime));
170 lvb->lvb_mtime = LTIME_S(dentry->d_inode->i_mtime);
172 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb blocks from disk: "
173 LPU64" -> %lu\n", res->lr_name.name[0],
174 lvb->lvb_blocks, dentry->d_inode->i_blocks);
175 lvb->lvb_blocks = dentry->d_inode->i_blocks;
180 up(&res->lr_lvb_sem);
186 struct ldlm_valblock_ops filter_lvbo = {
187 lvbo_init: filter_lvbo_init,
188 lvbo_update: filter_lvbo_update