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,
104 static int lov_llog_origin_connect(struct llog_ctxt *ctxt, int count,
105 struct llog_logid *logid,
106 struct llog_gen *gen,
107 struct obd_uuid *uuid)
109 struct obd_device *obd = ctxt->loc_obd;
110 struct lov_obd *lov = &obd->u.lov;
111 int i, rc = 0, err = 0;
115 for (i = 0; i < count; i++) {
116 struct obd_device *child;
117 struct llog_ctxt *cctxt;
119 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
121 if (uuid && !obd_uuid_equals(uuid, &lov->lov_tgts[i]->ltd_uuid))
123 CDEBUG(D_CONFIG, "connect %d/%d\n", i, count);
124 child = lov->lov_tgts[i]->ltd_exp->exp_obd;
125 cctxt = llog_get_context(child, ctxt->loc_idx);
126 rc = llog_connect(cctxt, 1, logid, gen, uuid);
127 llog_ctxt_put(cctxt);
130 CERROR("error osc_llog_connect tgt %d (%d)\n", i, rc);
140 /* the replicators commit callback */
141 static int lov_llog_repl_cancel(struct llog_ctxt *ctxt, struct lov_stripe_md *lsm,
142 int count, struct llog_cookie *cookies, int flags)
145 struct obd_device *obd = ctxt->loc_obd;
149 LASSERT(lsm != NULL);
150 LASSERT(count == lsm->lsm_stripe_count);
154 for (i = 0; i < count; i++, cookies++) {
155 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
156 struct obd_device *child =
157 lov->lov_tgts[loi->loi_ost_idx]->ltd_exp->exp_obd;
158 struct llog_ctxt *cctxt =
159 llog_get_context(child, ctxt->loc_idx);
162 err = llog_cancel(cctxt, NULL, 1, cookies, flags);
163 llog_ctxt_put(cctxt);
164 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
165 CERROR("error: objid "LPX64" subobj "LPX64
166 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
167 loi->loi_id, loi->loi_ost_idx, err);
176 static struct llog_operations lov_mds_ost_orig_logops = {
177 lop_add: lov_llog_origin_add,
178 lop_connect: lov_llog_origin_connect
181 static struct llog_operations lov_size_repl_logops = {
182 lop_cancel: lov_llog_repl_cancel
185 int lov_llog_init(struct obd_device *obd, struct obd_llog_group *olg,
186 struct obd_device *tgt, int count, struct llog_catid *logid,
187 struct obd_uuid *uuid)
189 struct lov_obd *lov = &obd->u.lov;
190 struct obd_device *child;
191 int i, rc = 0, err = 0;
194 LASSERT(olg == &obd->obd_olg);
195 rc = llog_setup(obd, olg, LLOG_MDS_OST_ORIG_CTXT, tgt, 0, NULL,
196 &lov_mds_ost_orig_logops);
200 rc = llog_setup(obd, olg, LLOG_SIZE_REPL_CTXT, tgt, 0, NULL,
201 &lov_size_repl_logops);
206 /* count may not match lov->desc.ld_tgt_count during dynamic ost add */
207 for (i = 0; i < count; i++) {
208 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
210 if (uuid && !obd_uuid_equals(uuid, &lov->lov_tgts[i]->ltd_uuid))
212 CDEBUG(D_CONFIG, "init %d/%d\n", i, count);
213 LASSERT(lov->lov_tgts[i]->ltd_exp);
214 child = lov->lov_tgts[i]->ltd_exp->exp_obd;
215 rc = obd_llog_init(child, &child->obd_olg, tgt, 1, logid + i, uuid);
217 CERROR("error osc_llog_init idx %d osc '%s' tgt '%s' "
218 "(rc=%d)\n", i, child->obd_name, tgt->obd_name,
228 int lov_llog_finish(struct obd_device *obd, int count)
230 struct llog_ctxt *ctxt;
234 /* cleanup our llogs only if the ctxts have been setup
235 * (client lov doesn't setup, mds lov does). */
236 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
238 rc = llog_cleanup(ctxt);
240 ctxt = llog_get_context(obd, LLOG_SIZE_REPL_CTXT);
242 rc2 = llog_cleanup(ctxt);
246 /* lov->tgt llogs are cleaned during osc_cleanup. */