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.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * lustre/lov/lov_log.c
36 * Author: Phil Schwan <phil@clusterfs.com>
37 * Author: Peter Braam <braam@clusterfs.com>
38 * Author: Mike Shaver <shaver@clusterfs.com>
41 #define DEBUG_SUBSYSTEM S_LOV
43 #include <libcfs/libcfs.h>
45 #include <liblustre.h>
48 #include <obd_support.h>
49 #include <lustre_lib.h>
50 #include <lustre_net.h>
51 #include <lustre/lustre_idl.h>
52 #include <lustre_dlm.h>
53 #include <lustre_mds.h>
54 #include <obd_class.h>
57 #include <lprocfs_status.h>
59 #include "lov_internal.h"
61 /* Add log records for each OSC that this object is striped over, and return
62 * cookies for each one. We _would_ have nice abstraction here, except that
63 * we need to keep cookies in stripe order, even if some are NULL, so that
64 * the right cookies are passed back to the right OSTs at the client side.
65 * Unset cookies should be all-zero (which will never occur naturally). */
66 static int lov_llog_origin_add(struct llog_ctxt *ctxt, struct llog_rec_hdr *rec,
67 struct lov_stripe_md *lsm,
68 struct llog_cookie *logcookies, int numcookies)
70 struct obd_device *obd = ctxt->loc_obd;
71 struct lov_obd *lov = &obd->u.lov;
72 int i, rc = 0, cookies = 0;
75 LASSERTF(logcookies && numcookies >= lsm->lsm_stripe_count,
76 "logcookies %p, numcookies %d lsm->lsm_stripe_count %d \n",
77 logcookies, numcookies, lsm->lsm_stripe_count);
79 for (i = 0; i < lsm->lsm_stripe_count; i++) {
80 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
81 struct obd_device *child =
82 lov->lov_tgts[loi->loi_ost_idx]->ltd_exp->exp_obd;
83 struct llog_ctxt *cctxt = llog_get_context(child, ctxt->loc_idx);
85 /* fill mds unlink/setattr log record */
86 switch (rec->lrh_type) {
87 case MDS_UNLINK_REC: {
88 struct llog_unlink_rec *lur = (struct llog_unlink_rec *)rec;
89 lur->lur_oid = loi->loi_id;
90 lur->lur_oseq = loi->loi_seq;
93 case MDS_SETATTR_REC: {
94 struct llog_setattr_rec *lsr = (struct llog_setattr_rec *)rec;
95 lsr->lsr_oid = loi->loi_id;
96 lsr->lsr_oseq = loi->loi_seq;
99 case MDS_SETATTR64_REC: {
100 struct llog_setattr64_rec *lsr = (struct llog_setattr64_rec *)rec;
101 lsr->lsr_oid = loi->loi_id;
102 lsr->lsr_oseq = loi->loi_seq;
108 /* inject error in llog_add() below */
109 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_FAIL_LOV_LOG_ADD)) {
110 llog_ctxt_put(cctxt);
113 rc = llog_add(cctxt, rec, NULL, logcookies + cookies,
114 numcookies - cookies);
115 llog_ctxt_put(cctxt);
117 CERROR("Can't add llog (rc = %d) for stripe %d\n",
119 memset(logcookies + cookies, 0,
120 sizeof(struct llog_cookie));
121 rc = 1; /* skip this cookie */
123 /* Note that rc is always 1 if llog_add was successful */
129 static int lov_llog_origin_connect(struct llog_ctxt *ctxt,
130 struct llog_logid *logid,
131 struct llog_gen *gen,
132 struct obd_uuid *uuid)
134 struct obd_device *obd = ctxt->loc_obd;
135 struct lov_obd *lov = &obd->u.lov;
136 int i, rc = 0, err = 0;
140 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
141 struct obd_device *child;
142 struct llog_ctxt *cctxt;
144 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
146 if (uuid && !obd_uuid_equals(uuid, &lov->lov_tgts[i]->ltd_uuid))
148 CDEBUG(D_CONFIG, "connect %d/%d\n", i, lov->desc.ld_tgt_count);
149 child = lov->lov_tgts[i]->ltd_exp->exp_obd;
150 cctxt = llog_get_context(child, ctxt->loc_idx);
151 rc = llog_connect(cctxt, logid, gen, uuid);
152 llog_ctxt_put(cctxt);
155 CERROR("error osc_llog_connect tgt %d (%d)\n", i, rc);
165 /* the replicators commit callback */
166 static int lov_llog_repl_cancel(struct llog_ctxt *ctxt, struct lov_stripe_md *lsm,
167 int count, struct llog_cookie *cookies, int flags)
170 struct obd_device *obd = ctxt->loc_obd;
174 LASSERT(lsm != NULL);
175 LASSERT(count == lsm->lsm_stripe_count);
179 for (i = 0; i < count; i++, cookies++) {
180 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
181 struct obd_device *child =
182 lov->lov_tgts[loi->loi_ost_idx]->ltd_exp->exp_obd;
183 struct llog_ctxt *cctxt =
184 llog_get_context(child, ctxt->loc_idx);
187 err = llog_cancel(cctxt, NULL, 1, cookies, flags);
188 llog_ctxt_put(cctxt);
189 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
190 CERROR("error: objid "LPX64" subobj "LPX64
191 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
192 loi->loi_id, loi->loi_ost_idx, err);
201 static struct llog_operations lov_mds_ost_orig_logops = {
202 lop_add: lov_llog_origin_add,
203 lop_connect: lov_llog_origin_connect
206 static struct llog_operations lov_size_repl_logops = {
207 lop_cancel: lov_llog_repl_cancel
210 int lov_llog_init(struct obd_device *obd, struct obd_llog_group *olg,
211 struct obd_device *disk_obd, int *index)
213 struct lov_obd *lov = &obd->u.lov;
214 struct obd_device *child;
218 LASSERT(olg == &obd->obd_olg);
219 rc = llog_setup(obd, olg, LLOG_MDS_OST_ORIG_CTXT, disk_obd, 0, NULL,
220 &lov_mds_ost_orig_logops);
224 rc = llog_setup(obd, olg, LLOG_SIZE_REPL_CTXT, disk_obd, 0, NULL,
225 &lov_size_repl_logops);
227 GOTO(err_cleanup, rc);
230 /* count may not match lov->desc.ld_tgt_count during dynamic ost add */
231 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
232 if (!lov->lov_tgts[i])
235 if (index && i != *index)
238 child = lov->lov_tgts[i]->ltd_obd;
239 rc = obd_llog_init(child, &child->obd_olg, disk_obd, &i);
241 CERROR("error osc_llog_init idx %d osc '%s' tgt '%s' "
242 "(rc=%d)\n", i, child->obd_name,
243 disk_obd->obd_name, rc);
247 GOTO(err_cleanup, rc);
250 struct llog_ctxt *ctxt =
251 llog_get_context(obd, LLOG_SIZE_REPL_CTXT);
254 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
261 int lov_llog_finish(struct obd_device *obd, int count)
263 struct llog_ctxt *ctxt;
267 /* cleanup our llogs only if the ctxts have been setup
268 * (client lov doesn't setup, mds lov does). */
269 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
271 rc = llog_cleanup(ctxt);
273 ctxt = llog_get_context(obd, LLOG_SIZE_REPL_CTXT);
275 rc2 = llog_cleanup(ctxt);
279 /* lov->tgt llogs are cleaned during osc_cleanup. */