1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.sf.net/projects/lustre/
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #define DEBUG_SUBSYSTEM S_CMOBD
24 #include <linux/config.h>
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/obd_class.h>
28 #include <linux/lustre_net.h>
29 #include <linux/lustre_mds.h>
30 #include <linux/lustre_smfs.h>
31 #include "cmobd_internal.h"
33 /* If mdc_setattr is called with an 'iattr', then it is a normal RPC that
34 * should take the normal semaphore and go to the normal portal.
36 * If it is called with iattr->ia_valid & ATTR_FROM_OPEN, then it is a
37 * magic open-path setattr that should take the setattr semaphore and
38 * go to the setattr portal. */
39 int cmobd_setattr_reint(struct obd_device *obd, struct ptlrpc_request *req)
41 struct mds_rec_setattr *rec;
46 rec = (struct mds_rec_setattr *)lustre_msg_buf(req->rq_reqmsg, 0, 0);
49 if (rec->sa_valid & ATTR_FROM_OPEN)
50 req->rq_request_portal = MDS_SETATTR_PORTAL; //XXX FIXME bug 249
52 if (rec->sa_valid & (ATTR_MTIME | ATTR_CTIME))
53 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu\n",
54 ((time_t)rec->sa_mtime),
55 ((time_t)rec->sa_ctime));
56 size[0] = sizeof(struct mds_body);
57 req->rq_replen = lustre_msg_size(1, size);
59 rc = mdc_reint(req, NULL, LUSTRE_IMP_FULL);
61 if (rc == -ERESTARTSYS)
67 int cmobd_create_reint(struct obd_device *obd, struct ptlrpc_request *req)
69 int rc = 0, level, size[1];
72 size[0] = sizeof(struct mds_body);
73 req->rq_replen = lustre_msg_size(1, size);
75 level = LUSTRE_IMP_FULL;
77 rc = mdc_reint(req, NULL, level);
78 /* Resend if we were told to. */
79 if (rc == -ERESTARTSYS) {
80 level = LUSTRE_IMP_RECOVER;
85 mdc_store_inode_generation(NULL, req, 0, 0);
90 int cmobd_unlink_reint(struct obd_device *obd, struct ptlrpc_request *req)
95 size[0] = sizeof(struct mds_body);
96 size[1] = obd->u.cli.cl_max_mds_easize;
97 size[2] = obd->u.cli.cl_max_mds_cookiesize;
98 req->rq_replen = lustre_msg_size(3, size);
100 rc = mdc_reint(req, NULL, LUSTRE_IMP_FULL);
101 if (rc == -ERESTARTSYS)
106 int cmobd_link_reint(struct obd_device *obd, struct ptlrpc_request *req)
111 size[0] = sizeof(struct mds_body);
112 req->rq_replen = lustre_msg_size(1, size);
114 rc = mdc_reint(req, NULL, LUSTRE_IMP_FULL);
115 if (rc == -ERESTARTSYS)
121 int cmobd_rename_reint(struct obd_device *obd, struct ptlrpc_request *req)
126 size[0] = sizeof(struct mds_body);
127 size[1] = obd->u.cli.cl_max_mds_easize;
128 req->rq_replen = lustre_msg_size(2, size);
130 rc = mdc_reint(req, NULL, LUSTRE_IMP_FULL);
131 if (rc == -ERESTARTSYS)
137 typedef int (*cmobd_reint_mds_rec)(struct obd_device*,
138 struct ptlrpc_request *req);
140 static cmobd_reint_mds_rec cmobd_mds_reint[REINT_MAX + 1] = {
141 [REINT_SETATTR] cmobd_setattr_reint,
142 [REINT_CREATE] cmobd_create_reint,
143 [REINT_LINK] cmobd_link_reint,
144 [REINT_UNLINK] cmobd_unlink_reint,
145 [REINT_RENAME] cmobd_rename_reint,
148 int cmobd_reint_mds(struct obd_device *obd, void* record)
150 struct cache_manager_obd *cmobd = &obd->u.cmobd;
151 struct ptlrpc_request *req;
152 struct lustre_msg *msg;
153 struct mds_kml_pack_info *mkpi;
156 mkpi = (struct mds_kml_pack_info *)record;
158 req = ptlrpc_prep_req(class_exp2cliimp(cmobd->cm_master_exp),
159 MDS_REINT, mkpi->mpi_bufcount, mkpi->mpi_size,
163 record += sizeof(*mkpi);
164 msg = (struct lustre_msg *)record;
165 opcode = (__u32)*(int*)lustre_msg_buf(msg, 0, 0);
166 if (opcode > REINT_MAX || opcode <= 0) {
167 CERROR("Unrecorgnized reint opcode %u in cmobd mds reint\n",
169 GOTO(out, rc=-EINVAL);
172 memcpy(req->rq_reqmsg, record, mkpi->mpi_total_size);
173 /*flags and opc will be rewrite, so reset here
174 *FIXME maybe should set some flags in reint process*/
176 req->rq_reqmsg->opc = MDS_REINT;
177 req->rq_reqmsg->flags = 0;
179 rc = cmobd_mds_reint[opcode](cmobd->cm_master_obd, req);
181 ptlrpc_req_finished(req);