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 obdo *oa = NULL;
45 struct dentry *dentry;
50 /* we only want lvb's for object resources */
51 /* check for internal locks: these have name[1] != 0 */
52 if (res->lr_name.name[1])
55 down(&res->lr_lvb_sem);
59 OBD_ALLOC(lvb, sizeof(*lvb));
61 GOTO(out, rc = -ENOMEM);
63 res->lr_lvb_data = lvb;
64 res->lr_lvb_len = sizeof(*lvb);
66 obd = res->lr_namespace->ns_lvbp;
71 GOTO(out, rc = -ENOMEM);
73 oa->o_id = res->lr_name.name[0];
75 dentry = filter_oa2dentry(obd, oa);
77 GOTO(out, rc = PTR_ERR(dentry));
79 /* Limit the valid bits in the return data to what we actually use */
80 oa->o_valid = OBD_MD_FLID;
81 obdo_from_inode(oa, dentry->d_inode, FILTER_VALID_FLAGS);
84 lvb->lvb_size = dentry->d_inode->i_size;
85 lvb->lvb_mtime = LTIME_S(dentry->d_inode->i_mtime);
86 CDEBUG(D_DLMTRACE, "res: "LPU64" initial lvb size: "LPU64", mtime: "
87 LPU64"\n", res->lr_name.name[0], lvb->lvb_size, lvb->lvb_mtime);
92 if (rc && lvb != NULL) {
93 OBD_FREE(lvb, sizeof(*lvb));
94 res->lr_lvb_data = NULL;
101 /* This will be called in two ways:
103 * m != NULL : called by the DLM itself after a glimpse callback
104 * m == NULL : called by the filter after a disk write
106 static int filter_lvbo_update(struct ldlm_resource *res, struct lustre_msg *m,
110 struct ost_lvb *lvb = res->lr_lvb_data;
111 struct obd_device *obd;
112 struct obdo *oa = NULL;
113 struct dentry *dentry;
118 /* we only want lvb's for object resources */
119 /* check for internal locks: these have name[1] != 0 */
120 if (res->lr_name.name[1])
123 down(&res->lr_lvb_sem);
124 if (!res->lr_lvb_data) {
125 CERROR("No lvb when running lvbo_update!\n");
129 /* Update the LVB from the network message */
133 new = lustre_swab_buf(m, buf_idx, sizeof(*new),
134 lustre_swab_ost_lvb);
136 CERROR("lustre_swab_buf failed\n");
137 //GOTO(out, rc = -EPROTO);
140 if (new->lvb_size > lvb->lvb_size) {
141 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb size: "
142 LPU64" -> "LPU64"\n", res->lr_name.name[0],
143 lvb->lvb_size, new->lvb_size);
144 lvb->lvb_size = new->lvb_size;
146 if (new->lvb_mtime > lvb->lvb_mtime) {
147 CDEBUG(D_DLMTRACE, "res: "LPU64" updating lvb mtime: "
148 LPU64" -> "LPU64"\n", res->lr_name.name[0],
149 lvb->lvb_mtime, new->lvb_mtime);
150 lvb->lvb_mtime = new->lvb_mtime;
155 /* Update the LVB from the disk inode */
156 obd = res->lr_namespace->ns_lvbp;
161 GOTO(out, rc = -ENOMEM);
163 oa->o_id = res->lr_name.name[0];
165 dentry = filter_oa2dentry(obd, oa);
167 GOTO(out, rc = PTR_ERR(dentry));
169 /* Limit the valid bits in the return data to what we actually use */
170 oa->o_valid = OBD_MD_FLID;
171 obdo_from_inode(oa, dentry->d_inode, FILTER_VALID_FLAGS);
173 lvb->lvb_size = dentry->d_inode->i_size;
174 lvb->lvb_mtime = LTIME_S(dentry->d_inode->i_mtime);
175 CDEBUG(D_DLMTRACE, "res: "LPU64" disk lvb size: "LPU64", mtime: "
176 LPU64"\n", res->lr_name.name[0], lvb->lvb_size, lvb->lvb_mtime);
182 up(&res->lr_lvb_sem);
188 struct ldlm_valblock_ops filter_lvbo = {
189 lvbo_init: filter_lvbo_init,
190 lvbo_update: filter_lvbo_update