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) 2012, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mds/mds_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_MDS
45 #include <linux/module.h>
46 #include <linux/version.h>
48 #include <libcfs/list.h>
49 #include <obd_class.h>
50 #include <lustre_fsfilt.h>
51 #include <lustre_mds.h>
52 #include <lustre_log.h>
54 #include "mds_internal.h"
56 static int mds_llog_origin_add(const struct lu_env *env,
57 struct llog_ctxt *ctxt,
58 struct llog_rec_hdr *rec,
59 struct lov_stripe_md *lsm,
60 struct llog_cookie *logcookies, int numcookies)
62 struct obd_device *obd = ctxt->loc_obd;
63 struct obd_device *lov_obd = obd->u.mds.mds_lov_obd;
64 struct llog_ctxt *lctxt;
68 lctxt = llog_get_context(lov_obd, ctxt->loc_idx);
69 rc = llog_obd_add(env, lctxt, rec, lsm, logcookies, numcookies);
75 static int mds_llog_origin_connect(struct llog_ctxt *ctxt,
76 struct llog_logid *logid,
78 struct obd_uuid *uuid)
80 struct obd_device *obd = ctxt->loc_obd;
81 struct obd_device *lov_obd = obd->u.mds.mds_lov_obd;
82 struct llog_ctxt *lctxt;
86 lctxt = llog_get_context(lov_obd, ctxt->loc_idx);
87 rc = llog_connect(lctxt, logid, gen, uuid);
92 static struct llog_operations mds_ost_orig_logops = {
93 .lop_obd_add = mds_llog_origin_add,
94 .lop_connect = mds_llog_origin_connect,
97 static int mds_llog_repl_cancel(const struct lu_env *env,
98 struct llog_ctxt *ctxt,
99 struct lov_stripe_md *lsm,
100 int count, struct llog_cookie *cookies,
103 struct obd_device *obd = ctxt->loc_obd;
104 struct obd_device *lov_obd = obd->u.mds.mds_lov_obd;
105 struct llog_ctxt *lctxt;
109 lctxt = llog_get_context(lov_obd, ctxt->loc_idx);
110 rc = llog_cancel(env, lctxt, lsm, count, cookies, flags);
111 llog_ctxt_put(lctxt);
115 static struct llog_operations mds_size_repl_logops = {
116 lop_cancel: mds_llog_repl_cancel,
119 int mds_llog_init(struct obd_device *obd, struct obd_llog_group *olg,
120 struct obd_device *disk_obd, int *index)
122 struct obd_device *lov_obd = obd->u.mds.mds_lov_obd;
123 struct llog_ctxt *ctxt;
127 LASSERT(olg == &obd->obd_olg);
128 rc = llog_setup(NULL, obd, &obd->obd_olg, LLOG_MDS_OST_ORIG_CTXT,
129 disk_obd, &mds_ost_orig_logops);
133 rc = llog_setup(NULL, obd, &obd->obd_olg, LLOG_SIZE_REPL_CTXT,
134 disk_obd, &mds_size_repl_logops);
138 rc = obd_llog_init(lov_obd, &lov_obd->obd_olg, disk_obd, index);
140 CERROR("lov_llog_init err %d\n", rc);
141 GOTO(err_cleanup, rc);
146 ctxt = llog_get_context(obd, LLOG_SIZE_REPL_CTXT);
148 llog_cleanup(NULL, ctxt);
150 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
152 llog_cleanup(NULL, ctxt);
156 int mds_llog_finish(struct obd_device *obd, int count)
158 struct llog_ctxt *ctxt;
162 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
164 llog_cleanup(NULL, ctxt);
166 ctxt = llog_get_context(obd, LLOG_SIZE_REPL_CTXT);
168 llog_cleanup(NULL, ctxt);
173 static int mds_llog_add_unlink(struct obd_device *obd,
174 struct lov_stripe_md *lsm, obd_count count,
175 struct llog_cookie *logcookie, int cookies)
177 struct llog_unlink_rec *lur;
178 struct llog_ctxt *ctxt;
181 if (cookies < lsm->lsm_stripe_count)
184 /* first prepare unlink log record */
187 RETURN(rc = -ENOMEM);
188 lur->lur_hdr.lrh_len = lur->lur_tail.lrt_len = sizeof(*lur);
189 lur->lur_hdr.lrh_type = MDS_UNLINK_REC;
190 lur->lur_count = count;
192 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
193 rc = llog_obd_add(NULL, ctxt, &lur->lur_hdr, lsm, logcookie, cookies);
200 int mds_log_op_unlink(struct obd_device *obd,
201 struct lov_mds_md *lmm, int lmm_size,
202 struct llog_cookie *logcookies, int cookies_size)
204 struct mds_obd *mds = &obd->u.mds;
205 struct lov_stripe_md *lsm = NULL;
209 if (IS_ERR(mds->mds_lov_obd))
210 RETURN(PTR_ERR(mds->mds_lov_obd));
212 rc = obd_unpackmd(mds->mds_lov_exp, &lsm, lmm, lmm_size);
215 rc = mds_llog_add_unlink(obd, lsm, 0, logcookies,
216 cookies_size / sizeof(struct llog_cookie));
217 obd_free_memmd(mds->mds_lov_exp, &lsm);
220 EXPORT_SYMBOL(mds_log_op_unlink);
222 int mds_log_op_orphan(struct obd_device *obd, struct lov_stripe_md *lsm,
225 struct mds_obd *mds = &obd->u.mds;
226 struct llog_cookie logcookie;
230 if (IS_ERR(mds->mds_lov_obd))
231 RETURN(PTR_ERR(mds->mds_lov_obd));
233 rc = mds_llog_add_unlink(obd, lsm, count - 1, &logcookie, 1);