1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * Copyright (c) 2001-2003 Cluster File Systems, Inc.
7 * Author: Peter Braam <braam@clusterfs.com>
8 * Author: Andreas Dilger <adilger@clusterfs.com>
9 * Author: Phil Schwan <phil@clusterfs.com>
11 * This file is part of the Lustre file system, http://www.lustre.org
12 * Lustre is a trademark of Cluster File Systems, Inc.
14 * You may have signed or agreed to another license before downloading
15 * this software. If so, you are bound by the terms and conditions
16 * of that agreement, and the following does not apply to you. See the
17 * LICENSE file included with this distribution for more information.
19 * If you did not agree to a different license, then this copy of Lustre
20 * is open source software; you can redistribute it and/or modify it
21 * under the terms of version 2 of the GNU General Public License as
22 * published by the Free Software Foundation.
24 * In either case, Lustre is distributed in the hope that it will be
25 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
26 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * license text for more details.
30 #define DEBUG_SUBSYSTEM S_MDS
32 #ifndef AUTOCONF_INCLUDED
33 #include <linux/config.h>
35 #include <linux/module.h>
36 #include <linux/version.h>
38 #include <libcfs/list.h>
39 #include <obd_class.h>
40 #include <lustre_fsfilt.h>
41 #include <lustre_mds.h>
42 #include <lustre_commit_confd.h>
43 #include <lustre_log.h>
45 #include "mds_internal.h"
47 static int mds_llog_origin_add(struct llog_ctxt *ctxt,
48 struct llog_rec_hdr *rec, struct lov_stripe_md *lsm,
49 struct llog_cookie *logcookies, int numcookies)
51 struct obd_device *obd = ctxt->loc_obd;
52 struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
53 struct llog_ctxt *lctxt;
57 lctxt = llog_get_context(lov_obd, ctxt->loc_idx);
58 rc = llog_add(lctxt, rec, lsm, logcookies, numcookies);
62 static int mds_llog_origin_connect(struct llog_ctxt *ctxt, int count,
63 struct llog_logid *logid,
65 struct obd_uuid *uuid)
67 struct obd_device *obd = ctxt->loc_obd;
68 struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
69 struct llog_ctxt *lctxt;
73 lctxt = llog_get_context(lov_obd, ctxt->loc_idx);
74 rc = llog_connect(lctxt, count, logid, gen, uuid);
78 static int mds_llog_repl_cancel(struct llog_ctxt *ctxt, struct lov_stripe_md *lsm,
79 int count, struct llog_cookie *cookies, int flags)
81 struct obd_device *obd = ctxt->loc_obd;
82 struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
83 struct llog_ctxt *lctxt;
87 lctxt = llog_get_context(lov_obd, ctxt->loc_idx);
88 rc = llog_cancel(lctxt, lsm, count, cookies, flags);
92 int mds_log_op_unlink(struct obd_device *obd,
93 struct lov_mds_md *lmm, int lmm_size,
94 struct llog_cookie *logcookies, int cookies_size)
96 struct mds_obd *mds = &obd->u.mds;
97 struct lov_stripe_md *lsm = NULL;
98 struct llog_unlink_rec *lur;
99 struct llog_ctxt *ctxt;
103 if (IS_ERR(mds->mds_osc_obd))
104 RETURN(PTR_ERR(mds->mds_osc_obd));
106 rc = obd_unpackmd(mds->mds_osc_exp, &lsm, lmm, lmm_size);
109 rc = obd_checkmd(mds->mds_osc_exp, obd->obd_self_export, lsm);
112 /* first prepare unlink log record */
113 OBD_ALLOC(lur, sizeof(*lur));
115 GOTO(out, rc = -ENOMEM);
116 lur->lur_hdr.lrh_len = lur->lur_tail.lrt_len = sizeof(*lur);
117 lur->lur_hdr.lrh_type = MDS_UNLINK_REC;
119 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
120 rc = llog_add(ctxt, &lur->lur_hdr, lsm, logcookies,
121 cookies_size / sizeof(struct llog_cookie));
123 OBD_FREE(lur, sizeof(*lur));
125 obd_free_memmd(mds->mds_osc_exp, &lsm);
128 EXPORT_SYMBOL(mds_log_op_unlink);
129 int mds_log_op_setattr(struct obd_device *obd, __u32 uid, __u32 gid,
130 struct lov_mds_md *lmm, int lmm_size,
131 struct llog_cookie *logcookies, int cookies_size)
133 struct mds_obd *mds = &obd->u.mds;
134 struct lov_stripe_md *lsm = NULL;
135 struct llog_setattr_rec *lsr;
136 struct llog_ctxt *ctxt;
140 if (IS_ERR(mds->mds_osc_obd))
141 RETURN(PTR_ERR(mds->mds_osc_obd));
143 rc = obd_unpackmd(mds->mds_osc_exp, &lsm, lmm, lmm_size);
147 rc = obd_checkmd(mds->mds_osc_exp, obd->obd_self_export, lsm);
151 OBD_ALLOC(lsr, sizeof(*lsr));
153 GOTO(out, rc = -ENOMEM);
155 /* prepare setattr log record */
156 lsr->lsr_hdr.lrh_len = lsr->lsr_tail.lrt_len = sizeof(*lsr);
157 lsr->lsr_hdr.lrh_type = MDS_SETATTR_REC;
161 /* write setattr log */
162 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
163 rc = llog_add(ctxt, &lsr->lsr_hdr, lsm, logcookies,
164 cookies_size / sizeof(struct llog_cookie));
166 OBD_FREE(lsr, sizeof(*lsr));
168 obd_free_memmd(mds->mds_osc_exp, &lsm);
171 EXPORT_SYMBOL(mds_log_op_setattr);
173 static struct llog_operations mds_ost_orig_logops = {
174 lop_add: mds_llog_origin_add,
175 lop_connect: mds_llog_origin_connect,
178 static struct llog_operations mds_size_repl_logops = {
179 lop_cancel: mds_llog_repl_cancel,
182 int mds_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
183 struct obd_device *tgt, int count, struct llog_catid *logid,
184 struct obd_uuid *uuid)
186 struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
190 rc = llog_setup(obd, llogs, LLOG_MDS_OST_ORIG_CTXT, tgt, 0, NULL,
191 &mds_ost_orig_logops);
195 rc = llog_setup(obd, llogs, LLOG_SIZE_REPL_CTXT, tgt, 0, NULL,
196 &mds_size_repl_logops);
200 rc = obd_llog_init(lov_obd, llogs, tgt, count, logid, uuid);
202 CERROR("lov_llog_init err %d\n", rc);
207 int mds_llog_finish(struct obd_device *obd, int count)
209 struct llog_ctxt *ctxt;
213 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
215 rc = llog_cleanup(ctxt);
217 ctxt = llog_get_context(obd, LLOG_SIZE_REPL_CTXT);
219 rc2 = llog_cleanup(ctxt);