1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5 * Author: Phil Schwan <phil@clusterfs.com>
6 * Peter Braam <braam@clusterfs.com>
7 * Mike Shaver <shaver@clusterfs.com>
9 * This file is part of the Lustre file system, http://www.lustre.org
10 * Lustre is a trademark of Cluster File Systems, Inc.
12 * You may have signed or agreed to another license before downloading
13 * this software. If so, you are bound by the terms and conditions
14 * of that agreement, and the following does not apply to you. See the
15 * LICENSE file included with this distribution for more information.
17 * If you did not agree to a different license, then this copy of Lustre
18 * is open source software; you can redistribute it and/or modify it
19 * under the terms of version 2 of the GNU General Public License as
20 * published by the Free Software Foundation.
22 * In either case, Lustre is distributed in the hope that it will be
23 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
24 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * license text for more details.
29 # define EXPORT_SYMTAB
31 #define DEBUG_SUBSYSTEM S_LOV
33 #include <libcfs/libcfs.h>
35 #include <liblustre.h>
38 #include <obd_support.h>
39 #include <lustre_lib.h>
40 #include <lustre_net.h>
41 #include <lustre/lustre_idl.h>
42 #include <lustre_dlm.h>
43 #include <lustre_mds.h>
44 #include <obd_class.h>
47 #include <lprocfs_status.h>
49 #include "lov_internal.h"
51 /* Add log records for each OSC that this object is striped over, and return
52 * cookies for each one. We _would_ have nice abstraction here, except that
53 * we need to keep cookies in stripe order, even if some are NULL, so that
54 * the right cookies are passed back to the right OSTs at the client side.
55 * Unset cookies should be all-zero (which will never occur naturally). */
56 static int lov_llog_origin_add(struct llog_ctxt *ctxt,
57 struct llog_rec_hdr *rec, struct lov_stripe_md *lsm,
58 struct llog_cookie *logcookies, int numcookies)
60 struct obd_device *obd = ctxt->loc_obd;
61 struct lov_obd *lov = &obd->u.lov;
65 LASSERTF(logcookies && numcookies >= lsm->lsm_stripe_count,
66 "logcookies %p, numcookies %d lsm->lsm_stripe_count %d \n",
67 logcookies, numcookies, lsm->lsm_stripe_count);
69 for (i = 0; i < lsm->lsm_stripe_count; i++) {
70 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
71 struct obd_device *child =
72 lov->lov_tgts[loi->loi_ost_idx]->ltd_exp->exp_obd;
73 struct llog_ctxt *cctxt = llog_get_context(child, ctxt->loc_idx);
75 /* fill mds unlink/setattr log record */
76 switch (rec->lrh_type) {
77 case MDS_UNLINK_REC: {
78 struct llog_unlink_rec *lur = (struct llog_unlink_rec *)rec;
79 lur->lur_oid = loi->loi_id;
80 lur->lur_ogen = loi->loi_gr;
83 case MDS_SETATTR_REC: {
84 struct llog_setattr_rec *lsr = (struct llog_setattr_rec *)rec;
85 lsr->lsr_oid = loi->loi_id;
86 lsr->lsr_ogen = loi->loi_gr;
92 LASSERT(lsm->lsm_object_gr == loi->loi_gr);
93 rc1 = llog_add(cctxt, rec, NULL, logcookies + rc,
103 static int lov_llog_origin_connect(struct llog_ctxt *ctxt, int count,
104 struct llog_logid *logid,
105 struct llog_gen *gen,
106 struct obd_uuid *uuid)
108 struct obd_device *obd = ctxt->loc_obd;
109 struct lov_obd *lov = &obd->u.lov;
110 int i, rc = 0, err = 0;
114 for (i = 0; i < count; i++) {
115 struct obd_device *child;
116 struct llog_ctxt *cctxt;
118 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
120 if (uuid && !obd_uuid_equals(uuid, &lov->lov_tgts[i]->ltd_uuid))
122 CDEBUG(D_CONFIG, "connect %d/%d\n", i, count);
123 child = lov->lov_tgts[i]->ltd_exp->exp_obd;
124 cctxt = llog_get_context(child, ctxt->loc_idx);
125 rc = llog_connect(cctxt, 1, logid, gen, uuid);
127 CERROR("error osc_llog_connect tgt %d (%d)\n", i, rc);
137 /* the replicators commit callback */
138 static int lov_llog_repl_cancel(struct llog_ctxt *ctxt, struct lov_stripe_md *lsm,
139 int count, struct llog_cookie *cookies, int flags)
142 struct obd_device *obd = ctxt->loc_obd;
146 LASSERT(lsm != NULL);
147 LASSERT(count == lsm->lsm_stripe_count);
151 for (i = 0; i < count; i++, cookies++) {
152 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
153 struct obd_device *child =
154 lov->lov_tgts[loi->loi_ost_idx]->ltd_exp->exp_obd;
155 struct llog_ctxt *cctxt =
156 llog_get_context(child, ctxt->loc_idx);
159 err = llog_cancel(cctxt, NULL, 1, cookies, flags);
160 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
161 CERROR("error: objid "LPX64" subobj "LPX64
162 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
163 loi->loi_id, loi->loi_ost_idx, err);
172 static struct llog_operations lov_mds_ost_orig_logops = {
173 lop_add: lov_llog_origin_add,
174 lop_connect: lov_llog_origin_connect
177 static struct llog_operations lov_size_repl_logops = {
178 lop_cancel: lov_llog_repl_cancel
181 int lov_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
182 struct obd_device *tgt, int count, struct llog_catid *logid,
183 struct obd_uuid *uuid)
185 struct lov_obd *lov = &obd->u.lov;
186 struct obd_device *child;
187 int i, rc = 0, err = 0;
190 rc = llog_setup(obd, llogs, LLOG_MDS_OST_ORIG_CTXT, tgt, 0, NULL,
191 &lov_mds_ost_orig_logops);
195 rc = llog_setup(obd, llogs, LLOG_SIZE_REPL_CTXT, tgt, 0, NULL,
196 &lov_size_repl_logops);
201 /* count may not match lov->desc.ld_tgt_count during dynamic ost add */
202 for (i = 0; i < count; i++) {
203 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
205 if (uuid && !obd_uuid_equals(uuid, &lov->lov_tgts[i]->ltd_uuid))
207 CDEBUG(D_CONFIG, "init %d/%d\n", i, count);
208 LASSERT(lov->lov_tgts[i]->ltd_exp);
209 child = lov->lov_tgts[i]->ltd_exp->exp_obd;
210 rc = obd_llog_init(child, llogs, tgt, 1, logid + i, uuid);
212 CERROR("error osc_llog_init idx %d osc '%s' tgt '%s' "
213 "(rc=%d)\n", i, child->obd_name, tgt->obd_name,
223 int lov_llog_finish(struct obd_device *obd, int count)
225 struct llog_ctxt *ctxt;
229 /* cleanup our llogs only if the ctxts have been setup
230 * (client lov doesn't setup, mds lov does). */
231 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
233 rc = llog_cleanup(ctxt);
235 ctxt = llog_get_context(obd, LLOG_SIZE_REPL_CTXT);
237 rc2 = llog_cleanup(ctxt);
241 /* lov->tgt llogs are cleaned during osc_cleanup. */