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 LTIME_S(((time_t)rec->sa_mtime)),
55 LTIME_S(((time_t)rec->sa_ctime)));
57 size[0] = sizeof(struct mds_body);
58 req->rq_replen = lustre_msg_size(1, size);
60 rc = mdc_reint(req, NULL, LUSTRE_IMP_FULL);
62 if (rc == -ERESTARTSYS)
68 int cmobd_create_reint(struct obd_device *obd, struct ptlrpc_request *req)
70 int rc = 0, level, size[1];
73 size[0] = sizeof(struct mds_body);
74 req->rq_replen = lustre_msg_size(1, size);
76 level = LUSTRE_IMP_FULL;
78 rc = mdc_reint(req, NULL, level);
79 /* Resend if we were told to. */
80 if (rc == -ERESTARTSYS) {
81 level = LUSTRE_IMP_RECOVER;
86 mdc_store_inode_generation(NULL, req, 0, 0);
91 int cmobd_unlink_reint(struct obd_device *obd, struct ptlrpc_request *req)
96 size[0] = sizeof(struct mds_body);
97 size[1] = obd->u.cli.cl_max_mds_easize;
98 size[2] = obd->u.cli.cl_max_mds_cookiesize;
99 req->rq_replen = lustre_msg_size(3, size);
101 rc = mdc_reint(req, NULL, LUSTRE_IMP_FULL);
102 if (rc == -ERESTARTSYS)
107 int cmobd_link_reint(struct obd_device *obd, struct ptlrpc_request *req)
112 size[0] = sizeof(struct mds_body);
113 req->rq_replen = lustre_msg_size(1, size);
115 rc = mdc_reint(req, NULL, LUSTRE_IMP_FULL);
116 if (rc == -ERESTARTSYS)
122 int cmobd_rename_reint(struct obd_device *obd, struct ptlrpc_request *req)
127 size[0] = sizeof(struct mds_body);
128 size[1] = obd->u.cli.cl_max_mds_easize;
129 req->rq_replen = lustre_msg_size(2, size);
131 rc = mdc_reint(req, NULL, LUSTRE_IMP_FULL);
132 if (rc == -ERESTARTSYS)
138 typedef int (*cmobd_reint_mds_rec)(struct obd_device*,
139 struct ptlrpc_request *req);
141 static cmobd_reint_mds_rec cmobd_mds_reint[REINT_MAX + 1] = {
142 [REINT_SETATTR] cmobd_setattr_reint,
143 [REINT_CREATE] cmobd_create_reint,
144 [REINT_LINK] cmobd_link_reint,
145 [REINT_UNLINK] cmobd_unlink_reint,
146 [REINT_RENAME] cmobd_rename_reint,
149 int cmobd_reint_mds(struct obd_device *obd, void* record)
151 struct cache_manager_obd *cmobd = &obd->u.cmobd;
152 struct ptlrpc_request *req;
153 struct lustre_msg *msg;
154 struct mds_kml_pack_info *mkpi;
157 mkpi = (struct mds_kml_pack_info *)record;
159 req = ptlrpc_prep_req(class_exp2cliimp(cmobd->cm_master_exp),
160 MDS_REINT, mkpi->mpi_bufcount, mkpi->mpi_size,
164 record += sizeof(*mkpi);
165 msg = (struct lustre_msg *)record;
166 opcode = (__u32)*(int*)lustre_msg_buf(msg, 0, 0);
167 if (opcode > REINT_MAX || opcode <= 0) {
168 CERROR("Unrecorgnized reint opcode %u in cmobd mds reint\n",
170 GOTO(out, rc=-EINVAL);
173 memcpy(req->rq_reqmsg, record, mkpi->mpi_total_size);
174 /*flags and opc will be rewrite, so reset here
175 *FIXME maybe should set some flags in reint process*/
177 req->rq_reqmsg->opc = MDS_REINT;
178 req->rq_reqmsg->flags = 0;
180 rc = cmobd_mds_reint[opcode](cmobd->cm_master_obd, req);
182 ptlrpc_req_finished(req);