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_fsfilt.h>
36 #include <linux/lustre_commit_confd.h>
38 #include "filter_internal.h"
40 int filter_log_sz_change(struct obd_device *obd,
41 struct lustre_id *id, __u32 io_epoch,
42 struct llog_cookie *logcookie,
45 struct llog_size_change_rec *lsc;
46 struct ost_filterdata *ofd;
47 struct llog_ctxt *ctxt;
52 ofd = (struct ost_filterdata *) LUSTRE_FILTERDATA(inode);
54 if (ofd && ofd->ofd_epoch >= io_epoch) {
55 if (ofd->ofd_epoch > io_epoch)
56 CERROR("client sent old epoch %d for obj ino %ld\n",
57 io_epoch, inode->i_ino);
62 if (ofd && ofd->ofd_epoch < io_epoch) {
63 ofd->ofd_epoch = io_epoch;
65 OBD_ALLOC(ofd, sizeof(*ofd));
67 GOTO(out, rc = -ENOMEM);
69 LUSTRE_FILTERDATA(inode) = (void *) ofd;
70 ofd->ofd_epoch = io_epoch;
72 /* the decision to write a record is now made, unlock */
75 OBD_ALLOC(lsc, sizeof(*lsc));
78 lsc->lsc_hdr.lrh_len = lsc->lsc_tail.lrt_len = sizeof(*lsc);
79 lsc->lsc_hdr.lrh_type = OST_SZ_REC;
81 lsc->lsc_io_epoch = io_epoch;
83 CDEBUG(D_ERROR, "new epoch %lu for "DLID4"\n",
84 (unsigned long) io_epoch, OLID4(id));
86 ctxt = llog_get_context(&obd->obd_llogs, LLOG_SIZE_ORIG_CTXT);
87 rc = llog_add(ctxt, &lsc->lsc_hdr, NULL, logcookie, 1, NULL,NULL,NULL);
88 OBD_FREE(lsc, sizeof(*lsc));
91 LASSERT(rc == sizeof(*logcookie));
99 struct obd_llogs * filter_grab_llog_for_group(struct obd_device *,
100 int, struct obd_export *);
102 /* When this (destroy) operation is committed, return the cancel cookie */
103 void filter_cancel_cookies_cb(struct obd_device *obd, __u64 transno,
104 void *cb_data, int error)
106 struct llog_cookie *cookie = cb_data;
107 struct obd_llogs *llogs = NULL;
108 struct llog_ctxt *ctxt;
110 /* we have to find context for right group */
111 llogs = filter_grab_llog_for_group(obd, cookie->lgc_lgl.lgl_ogr, NULL);
114 ctxt = llog_get_context(llogs, cookie->lgc_subsys + 1);
116 llog_cancel(ctxt, 1, cookie, 0, NULL);
118 CERROR("no valid context for group "LPU64"\n",
119 cookie->lgc_lgl.lgl_ogr);
121 CDEBUG(D_HA, "unknown group "LPU64"!\n", cookie->lgc_lgl.lgl_ogr);
124 OBD_FREE(cb_data, sizeof(struct llog_cookie));
127 /* Callback for processing the unlink log record received from MDS by
130 int filter_recov_log_unlink_cb(struct llog_handle *llh,
131 struct llog_rec_hdr *rec, void *data)
133 struct llog_ctxt *ctxt = llh->lgh_ctxt;
134 struct obd_device *obd = ctxt->loc_obd;
135 struct obd_export *exp = obd->obd_self_export;
136 struct llog_cookie cookie;
137 struct llog_gen_rec *lgr;
138 struct llog_unlink_rec *lur;
144 if (!(le32_to_cpu(llh->lgh_hdr->llh_flags) & LLOG_F_IS_PLAIN)) {
145 CERROR("log is not plain\n");
148 if (rec->lrh_type != MDS_UNLINK_REC &&
149 rec->lrh_type != LLOG_GEN_REC) {
150 CERROR("log record type error\n");
154 cookie.lgc_lgl = llh->lgh_id;
155 cookie.lgc_subsys = LLOG_UNLINK_ORIG_CTXT;
156 cookie.lgc_index = le32_to_cpu(rec->lrh_index);
158 if (rec->lrh_type == LLOG_GEN_REC) {
159 lgr = (struct llog_gen_rec *)rec;
160 if (llog_gen_lt(lgr->lgr_gen, ctxt->loc_gen))
163 rc = LLOG_PROC_BREAK;
164 CWARN("fetch generation log, send cookie\n");
165 llog_cancel(ctxt, 1, &cookie, 0, NULL);
169 lur = (struct llog_unlink_rec *)rec;
173 oa->o_valid |= OBD_MD_FLCOOKIE;
174 oa->o_id = lur->lur_oid;
175 oa->o_gr = lur->lur_ogen;
176 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
177 memcpy(obdo_logcookie(oa), &cookie, sizeof(cookie));
180 rc = obd_destroy(exp, oa, NULL, NULL);
183 CDEBUG(D_HA, "object already removed, send cookie\n");
184 llog_cancel(ctxt, 1, &cookie, 0, NULL);
189 CDEBUG(D_HA, "object: "LPU64" in record is destroyed\n", oid);