4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, Whamcloud, Inc.
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 #include <linux/module.h>
46 #include <linux/version.h>
48 #include <libcfs/list.h>
49 #include <obd_class.h>
50 #include <lustre_log.h>
51 #include <lustre_fsfilt.h>
52 #include "filter_internal.h"
54 int filter_log_sz_change(struct llog_handle *cathandle,
55 struct ll_fid *mds_fid,
57 struct llog_cookie *logcookie,
60 struct llog_size_change_rec *lsc;
62 struct ost_filterdata *ofd;
65 mutex_lock(&inode->i_mutex);
66 ofd = inode->i_private;
68 if (ofd && ofd->ofd_epoch >= ioepoch) {
69 if (ofd->ofd_epoch > ioepoch)
70 CERROR("client sent old epoch %d for obj ino %ld\n",
71 ioepoch, inode->i_ino);
72 mutex_unlock(&inode->i_mutex);
76 if (ofd && ofd->ofd_epoch < ioepoch) {
77 ofd->ofd_epoch = ioepoch;
79 OBD_ALLOC(ofd, sizeof(*ofd));
81 GOTO(out, rc = -ENOMEM);
83 inode->i_private = ofd;
84 ofd->ofd_epoch = ioepoch;
86 /* the decision to write a record is now made, unlock */
87 mutex_unlock(&inode->i_mutex);
89 OBD_ALLOC(lsc, sizeof(*lsc));
92 lsc->lsc_hdr.lrh_len = lsc->lsc_tail.lrt_len = sizeof(*lsc);
93 lsc->lsc_hdr.lrh_type = OST_SZ_REC;
94 lsc->lsc_fid = *mds_fid;
95 lsc->lsc_ioepoch = ioepoch;
97 rc = llog_cat_add_rec(cathandle, &lsc->lsc_hdr, logcookie, NULL);
98 OBD_FREE(lsc, sizeof(*lsc));
101 LASSERT(rc == sizeof(*logcookie));
109 /* When this (destroy) operation is committed, return the cancel cookie */
110 void filter_cancel_cookies_cb(struct obd_device *obd, __u64 transno,
111 void *cb_data, int error)
113 struct llog_cookie *cookie = cb_data;
114 struct obd_llog_group *olg;
115 struct llog_ctxt *ctxt;
118 /* we have to find context for right group */
119 if (error != 0 || obd->obd_stopping) {
120 CDEBUG(D_INODE, "not cancel logcookie err %d stopping %d \n",
121 error, obd->obd_stopping);
125 olg = filter_find_olg(obd, cookie->lgc_lgl.lgl_oseq);
127 CDEBUG(D_HA, "unknown group "LPU64"!\n", cookie->lgc_lgl.lgl_oseq);
131 ctxt = llog_group_get_ctxt(olg, cookie->lgc_subsys + 1);
133 CERROR("no valid context for group "LPU64"\n",
134 cookie->lgc_lgl.lgl_oseq);
138 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_CANCEL_COOKIE_TIMEOUT, 30);
140 rc = llog_cancel(ctxt, NULL, 1, cookie, 0);
142 CERROR("error cancelling log cookies: rc = %d\n", rc);
145 OBD_FREE(cookie, sizeof(*cookie));
148 /* Callback for processing the unlink log record received from MDS by
149 * llog_client_api. */
150 static int filter_recov_log_unlink_cb(struct llog_ctxt *ctxt,
151 struct llog_rec_hdr *rec,
152 struct llog_cookie *cookie)
154 struct obd_export *exp = ctxt->loc_obd->obd_self_export;
155 struct llog_unlink_rec *lur;
162 lur = (struct llog_unlink_rec *)rec;
166 oa->o_valid |= OBD_MD_FLCOOKIE;
167 oa->o_id = lur->lur_oid;
168 oa->o_seq = lur->lur_oseq;
169 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
170 oa->o_lcookie = *cookie;
172 /* objid gap may require to destroy several objects in row */
173 count = lur->lur_count + 1;
175 /* This check is only valid before FID-on-OST and it should
176 * be removed after FID-on-OST is implemented */
177 if (oa->o_seq > FID_SEQ_OST_MAX) {
178 CERROR("%s: invalid group number "LPU64" > MAX_CMD_GROUP %u\n",
179 exp->exp_obd->obd_name, oa->o_seq, FID_SEQ_OST_MAX);
184 rc = filter_destroy(NULL, exp, oa, NULL, NULL, NULL, NULL);
186 CDEBUG(D_RPCTRACE, "object "LPU64" is destroyed\n",
188 else if (rc != -ENOENT)
189 CEMERG("error destroying object "LPU64": %d\n",
201 /* Callback for processing the setattr log record received from MDS by
202 * llog_client_api. */
203 static int filter_recov_log_setattr_cb(struct llog_ctxt *ctxt,
204 struct llog_rec_hdr *rec,
205 struct llog_cookie *cookie)
207 struct obd_device *obd = ctxt->loc_obd;
208 struct obd_export *exp = obd->obd_self_export;
209 struct obd_info oinfo = { { { 0 } } };
214 OBDO_ALLOC(oinfo.oi_oa);
215 if (oinfo.oi_oa == NULL)
218 if (rec->lrh_type == MDS_SETATTR_REC) {
219 struct llog_setattr_rec *lsr = (struct llog_setattr_rec *)rec;
221 oinfo.oi_oa->o_id = lsr->lsr_oid;
222 oinfo.oi_oa->o_seq = lsr->lsr_oseq;
223 oinfo.oi_oa->o_uid = lsr->lsr_uid;
224 oinfo.oi_oa->o_gid = lsr->lsr_gid;
226 struct llog_setattr64_rec *lsr = (struct llog_setattr64_rec *)rec;
228 oinfo.oi_oa->o_id = lsr->lsr_oid;
229 oinfo.oi_oa->o_seq = lsr->lsr_oseq;
230 oinfo.oi_oa->o_uid = lsr->lsr_uid;
231 oinfo.oi_oa->o_gid = lsr->lsr_gid;
234 oinfo.oi_oa->o_valid |= (OBD_MD_FLID | OBD_MD_FLUID | OBD_MD_FLGID |
236 oinfo.oi_oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
237 oinfo.oi_oa->o_lcookie = *cookie;
238 oid = oinfo.oi_oa->o_id;
240 rc = filter_setattr(NULL, exp, &oinfo, NULL);
241 OBDO_FREE(oinfo.oi_oa);
244 CDEBUG(D_RPCTRACE, "object already removed, send cookie\n");
245 llog_cancel(ctxt, NULL, 1, cookie, 0);
250 CDEBUG(D_RPCTRACE, "object "LPU64" is chown/chgrp\n", oid);
255 int filter_recov_log_mds_ost_cb(struct llog_handle *llh,
256 struct llog_rec_hdr *rec, void *data)
258 struct llog_ctxt *ctxt = llh->lgh_ctxt;
259 struct llog_cookie cookie;
263 if (ctxt->loc_obd->obd_stopping)
264 RETURN(LLOG_PROC_BREAK);
267 cfs_spin_lock(&ctxt->loc_obd->u.filter.fo_flags_lock);
268 ctxt->loc_obd->u.filter.fo_mds_ost_sync = 0;
269 cfs_spin_unlock(&ctxt->loc_obd->u.filter.fo_flags_lock);
273 if (!(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN)) {
274 CERROR("log is not plain\n");
278 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_LLOG_RECOVERY_TIMEOUT, 30);
279 cookie.lgc_lgl = llh->lgh_id;
280 cookie.lgc_subsys = LLOG_MDS_OST_ORIG_CTXT;
281 cookie.lgc_index = rec->lrh_index;
283 switch (rec->lrh_type) {
285 rc = filter_recov_log_unlink_cb(ctxt, rec, &cookie);
287 case MDS_SETATTR_REC:
288 case MDS_SETATTR64_REC:
289 rc = filter_recov_log_setattr_cb(ctxt, rec, &cookie);
292 struct llog_gen_rec *lgr = (struct llog_gen_rec *)rec;
293 if (llog_gen_lt(lgr->lgr_gen, ctxt->loc_gen))
296 rc = LLOG_PROC_BREAK;
297 CDEBUG(D_HA, "fetch generation log, send cookie\n");
298 llog_cancel(ctxt, NULL, 1, &cookie, 0);
303 CERROR("log record type %08x unknown\n", rec->lrh_type);