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, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/lov/lov_log.c
38 * Author: Phil Schwan <phil@clusterfs.com>
39 * Author: Peter Braam <braam@clusterfs.com>
40 * Author: Mike Shaver <shaver@clusterfs.com>
43 #define DEBUG_SUBSYSTEM S_LOV
45 #include <libcfs/libcfs.h>
47 #include <liblustre.h>
50 #include <obd_support.h>
51 #include <lustre_lib.h>
52 #include <lustre_net.h>
53 #include <lustre/lustre_idl.h>
54 #include <lustre_dlm.h>
55 #include <lustre_mds.h>
56 #include <obd_class.h>
59 #include <lprocfs_status.h>
60 #include <lustre_log.h>
62 #include "lov_internal.h"
64 /* Add log records for each OSC that this object is striped over, and return
65 * cookies for each one. We _would_ have nice abstraction here, except that
66 * we need to keep cookies in stripe order, even if some are NULL, so that
67 * the right cookies are passed back to the right OSTs at the client side.
68 * Unset cookies should be all-zero (which will never occur naturally). */
69 static int lov_llog_origin_add(const struct lu_env *env,
70 struct llog_ctxt *ctxt,
71 struct llog_rec_hdr *rec,
72 struct lov_stripe_md *lsm,
73 struct llog_cookie *logcookies, int numcookies)
75 struct obd_device *obd = ctxt->loc_obd;
76 struct lov_obd *lov = &obd->u.lov;
77 int i, rc = 0, cookies = 0;
80 LASSERTF(logcookies && numcookies >= lsm->lsm_stripe_count,
81 "logcookies %p, numcookies %d lsm->lsm_stripe_count %d \n",
82 logcookies, numcookies, lsm->lsm_stripe_count);
84 for (i = 0; i < lsm->lsm_stripe_count; i++) {
85 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
86 struct obd_device *child =
87 lov->lov_tgts[loi->loi_ost_idx]->ltd_exp->exp_obd;
88 struct llog_ctxt *cctxt = llog_get_context(child, ctxt->loc_idx);
90 /* fill mds unlink/setattr log record */
91 switch (rec->lrh_type) {
92 case MDS_UNLINK_REC: {
93 struct llog_unlink_rec *lur = (struct llog_unlink_rec *)rec;
94 lur->lur_oid = ostid_id(&loi->loi_oi);
95 lur->lur_oseq = (__u32)ostid_seq(&loi->loi_oi);
98 case MDS_SETATTR64_REC: {
99 struct llog_setattr64_rec *lsr = (struct llog_setattr64_rec *)rec;
100 lsr->lsr_oi = loi->loi_oi;
107 /* inject error in llog_obd_add() below */
108 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_FAIL_LOV_LOG_ADD)) {
109 llog_ctxt_put(cctxt);
112 rc = llog_obd_add(env, cctxt, rec, NULL, logcookies + cookies,
113 numcookies - cookies);
114 llog_ctxt_put(cctxt);
116 CERROR("Can't add llog (rc = %d) for stripe %d\n",
118 memset(logcookies + cookies, 0,
119 sizeof(struct llog_cookie));
120 rc = 1; /* skip this cookie */
122 /* Note that rc is always 1 if llog_obd_add was successful */
128 static int lov_llog_origin_connect(struct llog_ctxt *ctxt,
129 struct llog_logid *logid,
130 struct llog_gen *gen,
131 struct obd_uuid *uuid)
133 struct obd_device *obd = ctxt->loc_obd;
134 struct lov_obd *lov = &obd->u.lov;
135 int i, rc = 0, err = 0;
139 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
140 struct obd_device *child;
141 struct llog_ctxt *cctxt;
143 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
145 if (uuid && !obd_uuid_equals(uuid, &lov->lov_tgts[i]->ltd_uuid))
147 CDEBUG(D_CONFIG, "connect %d/%d\n", i, lov->desc.ld_tgt_count);
148 child = lov->lov_tgts[i]->ltd_exp->exp_obd;
149 cctxt = llog_get_context(child, ctxt->loc_idx);
150 rc = llog_connect(cctxt, logid, gen, uuid);
151 llog_ctxt_put(cctxt);
154 CERROR("error osc_llog_connect tgt %d (%d)\n", i, rc);
164 /* the replicators commit callback */
165 static int lov_llog_repl_cancel(const struct lu_env *env,
166 struct llog_ctxt *ctxt,
167 struct lov_stripe_md *lsm,
168 int count, struct llog_cookie *cookies,
172 struct obd_device *obd = ctxt->loc_obd;
176 LASSERT(lsm != NULL);
177 LASSERT(count == lsm->lsm_stripe_count);
181 for (i = 0; i < count; i++, cookies++) {
182 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
183 struct obd_device *child =
184 lov->lov_tgts[loi->loi_ost_idx]->ltd_exp->exp_obd;
185 struct llog_ctxt *cctxt =
186 llog_get_context(child, ctxt->loc_idx);
189 err = llog_cancel(env, cctxt, NULL, 1, cookies, flags);
190 llog_ctxt_put(cctxt);
191 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
192 CERROR("%s: objid "DOSTID" subobj "DOSTID
193 " on OST idx %d: rc = %d\n",
194 obd->obd_name, POSTID(&lsm->lsm_oi),
195 POSTID(&loi->loi_oi), loi->loi_ost_idx, err);
204 static struct llog_operations lov_mds_ost_orig_logops = {
205 .lop_obd_add = lov_llog_origin_add,
206 .lop_connect = lov_llog_origin_connect,
209 static struct llog_operations lov_size_repl_logops = {
210 .lop_cancel = lov_llog_repl_cancel,
213 int lov_llog_init(struct obd_device *obd, struct obd_llog_group *olg,
214 struct obd_device *disk_obd, int *index)
216 struct lov_obd *lov = &obd->u.lov;
217 struct obd_device *child;
221 LASSERT(olg == &obd->obd_olg);
222 rc = llog_setup(NULL, obd, olg, LLOG_MDS_OST_ORIG_CTXT, disk_obd,
223 &lov_mds_ost_orig_logops);
227 rc = llog_setup(NULL, obd, olg, LLOG_SIZE_REPL_CTXT, disk_obd,
228 &lov_size_repl_logops);
230 GOTO(err_cleanup, rc);
233 /* count may not match lov->desc.ld_tgt_count during dynamic ost add */
234 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
235 if (!lov->lov_tgts[i])
238 if (index && i != *index)
241 child = lov->lov_tgts[i]->ltd_obd;
242 rc = obd_llog_init(child, &child->obd_olg, disk_obd, &i);
244 CERROR("error osc_llog_init idx %d osc '%s' tgt '%s' "
245 "(rc=%d)\n", i, child->obd_name,
246 disk_obd->obd_name, rc);
250 GOTO(err_cleanup, rc);
253 struct llog_ctxt *ctxt =
254 llog_get_context(obd, LLOG_SIZE_REPL_CTXT);
256 llog_cleanup(NULL, ctxt);
257 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
259 llog_cleanup(NULL, ctxt);
264 int lov_llog_finish(struct obd_device *obd, int count)
266 struct llog_ctxt *ctxt;
270 /* cleanup our llogs only if the ctxts have been setup
271 * (client lov doesn't setup, mds lov does). */
272 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
274 llog_cleanup(NULL, ctxt);
276 ctxt = llog_get_context(obd, LLOG_SIZE_REPL_CTXT);
278 llog_cleanup(NULL, ctxt);
280 /* lov->tgt llogs are cleaned during osc_cleanup. */