1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/obdfilter/filter_log.c
38 * Author: Peter Braam <braam@clusterfs.com>
39 * Author: Andreas Dilger <adilger@clusterfs.com>
40 * Author: Phil Schwan <phil@clusterfs.com>
43 #define DEBUG_SUBSYSTEM S_FILTER
45 #ifndef AUTOCONF_INCLUDED
46 #include <linux/config.h>
48 #include <linux/module.h>
49 #include <linux/version.h>
51 #include <libcfs/list.h>
52 #include <obd_class.h>
53 #include <lustre_log.h>
54 #include <lustre_fsfilt.h>
55 #include "filter_internal.h"
57 int filter_log_sz_change(struct llog_handle *cathandle,
58 struct ll_fid *mds_fid,
60 struct llog_cookie *logcookie,
63 struct llog_size_change_rec *lsc;
65 struct ost_filterdata *ofd;
68 LOCK_INODE_MUTEX(inode);
69 ofd = inode->i_filterdata;
71 if (ofd && ofd->ofd_epoch >= io_epoch) {
72 if (ofd->ofd_epoch > io_epoch)
73 CERROR("client sent old epoch %d for obj ino %ld\n",
74 io_epoch, inode->i_ino);
75 UNLOCK_INODE_MUTEX(inode);
79 if (ofd && ofd->ofd_epoch < io_epoch) {
80 ofd->ofd_epoch = io_epoch;
82 OBD_ALLOC(ofd, sizeof(*ofd));
84 GOTO(out, rc = -ENOMEM);
86 inode->i_filterdata = ofd;
87 ofd->ofd_epoch = io_epoch;
89 /* the decision to write a record is now made, unlock */
90 UNLOCK_INODE_MUTEX(inode);
92 OBD_ALLOC(lsc, sizeof(*lsc));
95 lsc->lsc_hdr.lrh_len = lsc->lsc_tail.lrt_len = sizeof(*lsc);
96 lsc->lsc_hdr.lrh_type = OST_SZ_REC;
97 lsc->lsc_fid = *mds_fid;
98 lsc->lsc_io_epoch = io_epoch;
100 rc = llog_cat_add_rec(cathandle, &lsc->lsc_hdr, logcookie, NULL);
101 OBD_FREE(lsc, sizeof(*lsc));
104 LASSERT(rc == sizeof(*logcookie));
112 /* When this (destroy) operation is committed, return the cancel cookie */
113 void filter_cancel_cookies_cb(struct obd_device *obd, __u64 transno,
114 void *cb_data, int error)
116 struct llog_cookie *cookie = cb_data;
117 struct llog_ctxt *ctxt;
120 if (error != 0 || obd->obd_stopping) {
121 CDEBUG(D_INODE, "not cancel logcookie err %d stopping %d \n",
122 error, obd->obd_stopping);
123 OBD_FREE(cookie, sizeof(*cookie));
127 ctxt = llog_get_context(obd, cookie->lgc_subsys + 1);
131 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_CANCEL_COOKIE_TIMEOUT, 30);
133 rc = llog_cancel(ctxt, NULL, 1, cookie, 0);
135 CERROR("error cancelling log cookies: rc = %d\n", rc);
138 OBD_FREE(cookie, sizeof(*cookie));
141 /* Callback for processing the unlink log record received from MDS by
142 * llog_client_api. */
143 static int filter_recov_log_unlink_cb(struct llog_ctxt *ctxt,
144 struct llog_rec_hdr *rec,
145 struct llog_cookie *cookie)
147 struct obd_export *exp = ctxt->loc_obd->obd_self_export;
148 struct llog_unlink_rec *lur;
155 lur = (struct llog_unlink_rec *)rec;
159 oa->o_valid |= OBD_MD_FLCOOKIE;
160 oa->o_id = lur->lur_oid;
161 oa->o_gr = lur->lur_ogr;
162 oa->o_lcookie = *cookie;
164 /* objid gap may require to destroy several objects in row */
165 count = lur->lur_count + 1;
168 rc = filter_destroy(exp, oa, NULL, NULL, NULL);
170 CDEBUG(D_RPCTRACE, "object "LPU64" is destroyed\n",
172 else if (rc != -ENOENT)
173 CEMERG("error destroying object "LPU64": %d\n",
185 /* Callback for processing the setattr log record received from MDS by
186 * llog_client_api. */
187 static int filter_recov_log_setattr_cb(struct llog_ctxt *ctxt,
188 struct llog_rec_hdr *rec,
189 struct llog_cookie *cookie)
191 struct obd_device *obd = ctxt->loc_obd;
192 struct obd_export *exp = obd->obd_self_export;
193 struct obd_info oinfo = { { { 0 } } };
198 OBDO_ALLOC(oinfo.oi_oa);
200 if (rec->lrh_type == MDS_SETATTR_REC) {
201 struct llog_setattr_rec *lsr = (struct llog_setattr_rec *)rec;
203 oinfo.oi_oa->o_id = lsr->lsr_oid;
204 oinfo.oi_oa->o_gr = lsr->lsr_ogr;
205 oinfo.oi_oa->o_uid = lsr->lsr_uid;
206 oinfo.oi_oa->o_gid = lsr->lsr_gid;
208 struct llog_setattr64_rec *lsr = (struct llog_setattr64_rec *)rec;
210 oinfo.oi_oa->o_id = lsr->lsr_oid;
211 oinfo.oi_oa->o_gr = lsr->lsr_ogr;
212 oinfo.oi_oa->o_uid = lsr->lsr_uid;
213 oinfo.oi_oa->o_gid = lsr->lsr_gid;
216 oinfo.oi_oa->o_valid |= (OBD_MD_FLID | OBD_MD_FLUID | OBD_MD_FLGID |
218 oinfo.oi_oa->o_lcookie = *cookie;
219 oid = oinfo.oi_oa->o_id;
221 rc = filter_setattr(exp, &oinfo, NULL);
222 OBDO_FREE(oinfo.oi_oa);
225 CDEBUG(D_RPCTRACE, "object already removed, send cookie\n");
226 llog_cancel(ctxt, NULL, 1, cookie, 0);
231 CDEBUG(D_RPCTRACE, "object "LPU64" is chown/chgrp\n", oid);
236 int filter_recov_log_mds_ost_cb(struct llog_handle *llh,
237 struct llog_rec_hdr *rec, void *data)
239 struct llog_ctxt *ctxt = llh->lgh_ctxt;
240 struct llog_cookie cookie;
244 if (ctxt->loc_obd->obd_stopping)
245 RETURN(LLOG_PROC_BREAK);
247 if (!(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN)) {
248 CERROR("log is not plain\n");
252 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_LLOG_RECOVERY_TIMEOUT, 30);
253 cookie.lgc_lgl = llh->lgh_id;
254 cookie.lgc_subsys = LLOG_MDS_OST_ORIG_CTXT;
255 cookie.lgc_index = rec->lrh_index;
257 switch (rec->lrh_type) {
259 rc = filter_recov_log_unlink_cb(ctxt, rec, &cookie);
261 case MDS_SETATTR_REC:
262 case MDS_SETATTR64_REC:
263 rc = filter_recov_log_setattr_cb(ctxt, rec, &cookie);
266 struct llog_gen_rec *lgr = (struct llog_gen_rec *)rec;
267 if (llog_gen_lt(lgr->lgr_gen, ctxt->loc_gen))
270 rc = LLOG_PROC_BREAK;
271 CDEBUG(D_HA, "fetch generation log, send cookie\n");
272 llog_cancel(ctxt, NULL, 1, &cookie, 0);
277 CERROR("log record type %08x unknown\n", rec->lrh_type);