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/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>
44 # define EXPORT_SYMTAB
46 #define DEBUG_SUBSYSTEM S_LOV
48 #include <libcfs/libcfs.h>
50 #include <liblustre.h>
53 #include <obd_support.h>
54 #include <lustre_lib.h>
55 #include <lustre_net.h>
56 #include <lustre/lustre_idl.h>
57 #include <lustre_dlm.h>
58 #include <lustre_mds.h>
59 #include <obd_class.h>
62 #include <lprocfs_status.h>
64 #include "lov_internal.h"
66 /* Add log records for each OSC that this object is striped over, and return
67 * cookies for each one. We _would_ have nice abstraction here, except that
68 * we need to keep cookies in stripe order, even if some are NULL, so that
69 * the right cookies are passed back to the right OSTs at the client side.
70 * Unset cookies should be all-zero (which will never occur naturally). */
71 static int lov_llog_origin_add(struct llog_ctxt *ctxt, 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;
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 = loi->loi_id;
95 lur->lur_ogen = loi->loi_gr;
98 case MDS_SETATTR_REC: {
99 struct llog_setattr_rec *lsr = (struct llog_setattr_rec *)rec;
100 lsr->lsr_oid = loi->loi_id;
101 lsr->lsr_ogen = loi->loi_gr;
104 case MDS_SETATTR64_REC: {
105 struct llog_setattr64_rec *lsr = (struct llog_setattr64_rec *)rec;
106 lsr->lsr_oid = loi->loi_id;
107 lsr->lsr_ogen = loi->loi_gr;
113 LASSERT(lsm->lsm_object_gr == loi->loi_gr);
114 rc1 = llog_add(cctxt, rec, NULL, logcookies + rc,
116 llog_ctxt_put(cctxt);
125 static int lov_llog_origin_connect(struct llog_ctxt *ctxt,
126 struct llog_logid *logid,
127 struct llog_gen *gen,
128 struct obd_uuid *uuid)
130 struct obd_device *obd = ctxt->loc_obd;
131 struct lov_obd *lov = &obd->u.lov;
132 int i, rc = 0, err = 0;
136 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
137 struct obd_device *child;
138 struct llog_ctxt *cctxt;
140 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
142 if (uuid && !obd_uuid_equals(uuid, &lov->lov_tgts[i]->ltd_uuid))
144 CDEBUG(D_CONFIG, "connect %d/%d\n", i, lov->desc.ld_tgt_count);
145 child = lov->lov_tgts[i]->ltd_exp->exp_obd;
146 cctxt = llog_get_context(child, ctxt->loc_idx);
147 rc = llog_connect(cctxt, logid, gen, uuid);
148 llog_ctxt_put(cctxt);
151 CERROR("error osc_llog_connect tgt %d (%d)\n", i, rc);
161 /* the replicators commit callback */
162 static int lov_llog_repl_cancel(struct llog_ctxt *ctxt, struct lov_stripe_md *lsm,
163 int count, struct llog_cookie *cookies, int flags)
166 struct obd_device *obd = ctxt->loc_obd;
170 LASSERT(lsm != NULL);
171 LASSERT(count == lsm->lsm_stripe_count);
175 for (i = 0; i < count; i++, cookies++) {
176 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
177 struct obd_device *child =
178 lov->lov_tgts[loi->loi_ost_idx]->ltd_exp->exp_obd;
179 struct llog_ctxt *cctxt =
180 llog_get_context(child, ctxt->loc_idx);
183 err = llog_cancel(cctxt, NULL, 1, cookies, flags);
184 llog_ctxt_put(cctxt);
185 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
186 CERROR("error: objid "LPX64" subobj "LPX64
187 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
188 loi->loi_id, loi->loi_ost_idx, err);
197 static struct llog_operations lov_mds_ost_orig_logops = {
198 lop_add: lov_llog_origin_add,
199 lop_connect: lov_llog_origin_connect
202 static struct llog_operations lov_size_repl_logops = {
203 lop_cancel: lov_llog_repl_cancel
206 int lov_llog_init(struct obd_device *obd, struct obd_llog_group *olg,
207 struct obd_device *tgt, int count, struct llog_catid *logid,
208 struct obd_uuid *uuid)
210 struct lov_obd *lov = &obd->u.lov;
211 struct obd_device *child;
215 /* allow init only one target at one time */
218 LASSERT(olg == &obd->obd_olg);
219 rc = llog_setup(obd, olg, LLOG_MDS_OST_ORIG_CTXT, tgt, 0, NULL,
220 &lov_mds_ost_orig_logops);
224 rc = llog_setup(obd, olg, LLOG_SIZE_REPL_CTXT, tgt, 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] || !lov->lov_tgts[i]->ltd_active)
234 if (!obd_uuid_equals(uuid, &lov->lov_tgts[i]->ltd_uuid))
237 LASSERT(lov->lov_tgts[i]->ltd_exp);
238 child = lov->lov_tgts[i]->ltd_exp->exp_obd;
239 rc = obd_llog_init(child, &child->obd_olg, tgt, 1, logid, uuid);
241 CERROR("error osc_llog_init idx %d osc '%s' tgt '%s' "
242 "(rc=%d)\n", i, child->obd_name, tgt->obd_name,
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. */