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 the Lustre file system, http://www.lustre.org
12 * Lustre is a trademark of Cluster File Systems, Inc.
14 * You may have signed or agreed to another license before downloading
15 * this software. If so, you are bound by the terms and conditions
16 * of that agreement, and the following does not apply to you. See the
17 * LICENSE file included with this distribution for more information.
19 * If you did not agree to a different license, then this copy of Lustre
20 * is open source software; you can redistribute it and/or modify it
21 * under the terms of version 2 of the GNU General Public License as
22 * published by the Free Software Foundation.
24 * In either case, Lustre is distributed in the hope that it will be
25 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
26 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * license text for more details.
30 #define DEBUG_SUBSYSTEM S_FILTER
32 #ifndef AUTOCONF_INCLUDED
33 #include <linux/config.h>
35 #include <linux/module.h>
36 #include <linux/version.h>
38 #include <libcfs/list.h>
39 #include <obd_class.h>
40 #include <lustre_fsfilt.h>
41 #include <lustre_commit_confd.h>
43 #include "filter_internal.h"
45 int filter_log_sz_change(struct llog_handle *cathandle,
46 struct ll_fid *mds_fid,
48 struct llog_cookie *logcookie,
51 struct llog_size_change_rec *lsc;
53 struct ost_filterdata *ofd;
56 LOCK_INODE_MUTEX(inode);
57 ofd = inode->i_filterdata;
59 if (ofd && ofd->ofd_epoch >= ioepoch) {
60 if (ofd->ofd_epoch > ioepoch)
61 CERROR("client sent old epoch %d for obj ino %ld\n",
62 ioepoch, inode->i_ino);
63 UNLOCK_INODE_MUTEX(inode);
67 if (ofd && ofd->ofd_epoch < ioepoch) {
68 ofd->ofd_epoch = ioepoch;
70 OBD_ALLOC(ofd, sizeof(*ofd));
72 GOTO(out, rc = -ENOMEM);
74 inode->i_filterdata = ofd;
75 ofd->ofd_epoch = ioepoch;
77 /* the decision to write a record is now made, unlock */
78 UNLOCK_INODE_MUTEX(inode);
80 OBD_ALLOC(lsc, sizeof(*lsc));
83 lsc->lsc_hdr.lrh_len = lsc->lsc_tail.lrt_len = sizeof(*lsc);
84 lsc->lsc_hdr.lrh_type = OST_SZ_REC;
85 lsc->lsc_fid = *mds_fid;
86 lsc->lsc_ioepoch = ioepoch;
88 rc = llog_cat_add_rec(cathandle, &lsc->lsc_hdr, logcookie, NULL);
89 OBD_FREE(lsc, sizeof(*lsc));
92 LASSERT(rc == sizeof(*logcookie));
100 /* When this (destroy) operation is committed, return the cancel cookie */
101 void filter_cancel_cookies_cb(struct obd_device *obd, __u64 transno,
102 void *cb_data, int error)
104 struct llog_cookie *cookie = cb_data;
105 struct obd_llogs *llogs;
106 struct llog_ctxt *ctxt;
108 /* we have to find context for right group */
110 CDEBUG(D_INODE, "not cancelling llog cookie on error %d\n",
114 llogs = filter_grab_llog_for_group(obd, cookie->lgc_lgl.lgl_ogr, NULL);
117 ctxt = llog_get_context_from_llogs(llogs, cookie->lgc_subsys + 1);
119 llog_cancel(ctxt, NULL, 1, cookie, 0);
121 CERROR("no valid context for group "LPU64"\n",
122 cookie->lgc_lgl.lgl_ogr);
124 CDEBUG(D_HA, "unknown group "LPU64"!\n", cookie->lgc_lgl.lgl_ogr);
127 OBD_FREE(cookie, sizeof(struct llog_cookie));
130 /* Callback for processing the unlink log record received from MDS by
131 * llog_client_api. */
132 static int filter_recov_log_unlink_cb(struct llog_ctxt *ctxt,
133 struct llog_rec_hdr *rec,
134 struct llog_cookie *cookie)
136 struct obd_device *obd = ctxt->loc_obd;
137 struct obd_export *exp = obd->obd_self_export;
138 struct llog_unlink_rec *lur;
144 lur = (struct llog_unlink_rec *)rec;
148 oa->o_valid |= OBD_MD_FLCOOKIE;
149 oa->o_id = lur->lur_oid;
150 oa->o_gr = lur->lur_ogen;
151 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
152 memcpy(obdo_logcookie(oa), cookie, sizeof(*cookie));
155 rc = filter_destroy(exp, oa, NULL, NULL, NULL);
158 CDEBUG(D_HA, "object already removed, send cookie\n");
159 llog_cancel(ctxt, NULL, 1, cookie, 0);
164 CDEBUG(D_HA, "object: "LPU64" in record is destroyed\n", oid);
169 /* Callback for processing the setattr log record received from MDS by
170 * llog_client_api. */
171 static int filter_recov_log_setattr_cb(struct llog_ctxt *ctxt,
172 struct llog_rec_hdr *rec,
173 struct llog_cookie *cookie)
175 struct obd_device *obd = ctxt->loc_obd;
176 struct obd_export *exp = obd->obd_self_export;
177 struct llog_setattr_rec *lsr;
178 struct obd_info oinfo = { { { 0 } } };
183 lsr = (struct llog_setattr_rec *)rec;
184 OBDO_ALLOC(oinfo.oi_oa);
185 if (oinfo.oi_oa == NULL)
188 oinfo.oi_oa->o_valid |= (OBD_MD_FLID | OBD_MD_FLUID | OBD_MD_FLGID |
190 oinfo.oi_oa->o_id = lsr->lsr_oid;
191 oinfo.oi_oa->o_gr = lsr->lsr_ogen;
192 oinfo.oi_oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
193 oinfo.oi_oa->o_uid = lsr->lsr_uid;
194 oinfo.oi_oa->o_gid = lsr->lsr_gid;
195 memcpy(obdo_logcookie(oinfo.oi_oa), cookie, sizeof(*cookie));
196 oid = oinfo.oi_oa->o_id;
198 rc = filter_setattr(exp, &oinfo, NULL);
199 OBDO_FREE(oinfo.oi_oa);
202 CDEBUG(D_HA, "object already removed, send cookie\n");
203 llog_cancel(ctxt, NULL, 1, cookie, 0);
208 CDEBUG(D_HA, "object: "LPU64" in record is chown/chgrp\n", oid);
213 int filter_recov_log_mds_ost_cb(struct llog_handle *llh,
214 struct llog_rec_hdr *rec, void *data)
216 struct llog_ctxt *ctxt = llh->lgh_ctxt;
217 struct llog_cookie cookie;
221 if (!(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN)) {
222 CERROR("log is not plain\n");
226 cookie.lgc_lgl = llh->lgh_id;
227 cookie.lgc_subsys = LLOG_MDS_OST_ORIG_CTXT;
228 cookie.lgc_index = rec->lrh_index;
230 switch (rec->lrh_type) {
232 rc = filter_recov_log_unlink_cb(ctxt, rec, &cookie);
234 case MDS_SETATTR_REC:
235 rc = filter_recov_log_setattr_cb(ctxt, rec, &cookie);
238 struct llog_gen_rec *lgr = (struct llog_gen_rec *)rec;
239 if (llog_gen_lt(lgr->lgr_gen, ctxt->loc_gen))
242 rc = LLOG_PROC_BREAK;
243 CDEBUG(D_HA, "fetch generation log, send cookie\n");
244 llog_cancel(ctxt, NULL, 1, &cookie, 0);
249 CERROR("log record type %08x unknown\n", rec->lrh_type);