Whamcloud - gitweb
smash the HEAD with the contents of b_cmd. HEAD_PRE_CMD_SMASH and
[fs/lustre-release.git] / lustre / mds / mds_log.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  lustre/mds/mds_log.c
5  *
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>
10  *
11  *   This file is part of Lustre, http://www.lustre.org.
12  *
13  *   Lustre is free software; you can redistribute it and/or
14  *   modify it under the terms of version 2 of the GNU General Public
15  *   License as published by the Free Software Foundation.
16  *
17  *   Lustre is distributed in the hope that it will be useful,
18  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *   GNU General Public License for more details.
21  *
22  *   You should have received a copy of the GNU General Public License
23  *   along with Lustre; if not, write to the Free Software
24  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25  */
26
27 #define DEBUG_SUBSYSTEM S_MDS
28
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/version.h>
32
33 #include <portals/list.h>
34 #include <linux/obd_class.h>
35 #include <linux/lustre_fsfilt.h>
36 #include <linux/lustre_commit_confd.h>
37
38 #include "mds_internal.h"
39
40 static int mds_llog_origin_add(struct llog_ctxt *ctxt,
41                         struct llog_rec_hdr *rec, struct lov_stripe_md *lsm,
42                         struct llog_cookie *logcookies, int numcookies)
43 {
44         struct obd_device *obd = ctxt->loc_obd;
45         struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
46         struct llog_ctxt *lctxt;
47         int rc;
48         ENTRY;
49
50         lctxt = llog_get_context(&lov_obd->obd_llogs, ctxt->loc_idx);
51         rc = llog_add(lctxt, rec, lsm, logcookies, numcookies);
52         RETURN(rc);
53 }
54
55 static int mds_llog_origin_connect(struct llog_ctxt *ctxt, int count,
56                                    struct llog_logid *logid,
57                                    struct llog_gen *gen,
58                                    struct obd_uuid *uuid)
59 {
60         struct obd_device *obd = ctxt->loc_obd;
61         struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
62         struct llog_ctxt *lctxt;
63         int rc;
64         ENTRY;
65
66         lctxt = llog_get_context(&lov_obd->obd_llogs, ctxt->loc_idx);
67         rc = llog_connect(lctxt, count, logid, gen, uuid);
68         RETURN(rc);
69 }
70
71 static int mds_llog_repl_cancel(struct llog_ctxt *ctxt, struct lov_stripe_md *lsm,
72                           int count, struct llog_cookie *cookies, int flags)
73 {
74         struct obd_device *obd = ctxt->loc_obd;
75         struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
76         struct llog_ctxt *lctxt;
77         int rc;
78         ENTRY;
79
80         lctxt = llog_get_context(&lov_obd->obd_llogs, ctxt->loc_idx);
81         rc = llog_cancel(lctxt, lsm, count, cookies,flags);
82         RETURN(rc);
83 }
84
85 int mds_log_op_unlink(struct obd_device *obd, struct inode *inode,
86                       struct lov_mds_md *lmm, int lmm_size,
87                       struct llog_cookie *logcookies, int cookies_size)
88 {
89         struct mds_obd *mds = &obd->u.mds;
90         struct lov_stripe_md *lsm = NULL;
91         struct llog_ctxt *ctxt;
92         int rc;
93         ENTRY;
94
95         if (IS_ERR(mds->mds_osc_obd))
96                 RETURN(PTR_ERR(mds->mds_osc_obd));
97
98         rc = obd_unpackmd(mds->mds_osc_exp, &lsm,
99                           lmm, lmm_size);
100         if (rc < 0)
101                 RETURN(rc);
102
103         ctxt = llog_get_context(&obd->obd_llogs, LLOG_UNLINK_ORIG_CTXT);
104         rc = llog_add(ctxt, NULL, lsm, logcookies,
105                       cookies_size / sizeof(struct llog_cookie));
106
107         obd_free_memmd(mds->mds_osc_exp, &lsm);
108
109         RETURN(rc);
110 }
111
112 static struct llog_operations mds_unlink_orig_logops = {
113         lop_add:        mds_llog_origin_add,
114         lop_connect:    mds_llog_origin_connect,
115 };
116
117 static struct llog_operations mds_size_repl_logops = {
118         lop_cancel:     mds_llog_repl_cancel
119 };
120
121 int mds_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
122                   struct obd_device *tgt, int count, struct llog_catid *logid)
123 {
124         struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
125         int rc;
126         ENTRY;
127
128         rc = llog_setup(obd, llogs, LLOG_UNLINK_ORIG_CTXT, tgt, 0, NULL,
129                         &mds_unlink_orig_logops);
130         if (rc)
131                 RETURN(rc);
132
133         rc = llog_setup(obd, llogs, LLOG_SIZE_REPL_CTXT, tgt, 0, NULL,
134                         &mds_size_repl_logops);
135         if (rc)
136                 RETURN(rc);
137
138         rc = obd_llog_init(lov_obd, &lov_obd->obd_llogs, tgt, count, logid);
139         if (rc)
140                 CERROR("error lov_llog_init\n");
141
142         RETURN(rc);
143 }
144
145 int mds_llog_finish(struct obd_device *obd, struct obd_llogs *llogs, int count)
146 {
147         struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
148         struct llog_ctxt *ctxt;
149         int rc;
150         ENTRY;
151
152         ctxt = llog_get_context(llogs, LLOG_UNLINK_ORIG_CTXT);
153         rc = llog_cleanup(ctxt);
154         if (rc)
155                 RETURN(rc);
156
157         ctxt = llog_get_context(llogs, LLOG_SIZE_REPL_CTXT);
158         rc = llog_cleanup(ctxt);
159         if (rc)
160                 RETURN(rc);
161
162         rc = obd_llog_finish(lov_obd, &lov_obd->obd_llogs, count);
163         if (rc)
164                 CERROR("error lov_llog_finish\n");
165
166         RETURN(rc);
167 }