1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001, 2002 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.
25 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/kernel.h>
29 #define DEBUG_SUBSYSTEM S_MDC
31 #include <linux/obd_class.h>
32 #include <linux/lustre_mds.h>
34 static int mdc_reint(struct ptlrpc_client *cl, struct ptlrpc_request *request, int level)
37 request->rq_level = level;
39 rc = ptlrpc_queue_wait(request);
40 rc = ptlrpc_check_status(request, rc);
42 CERROR("error in handling %d\n", rc);
47 int mdc_setattr(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
48 struct inode *inode, struct iattr *iattr,
49 struct ptlrpc_request **request)
51 struct mds_rec_setattr *rec;
52 struct ptlrpc_request *req;
53 int rc, size = sizeof(*rec);
56 req = ptlrpc_prep_req(cl, conn, MDS_REINT, 1, &size, NULL);
60 rec = lustre_msg_buf(req->rq_reqmsg, 0);
61 mds_setattr_pack(rec, inode, iattr);
63 size = sizeof(struct mds_body);
64 req->rq_replen = lustre_msg_size(1, &size);
66 rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
68 if (rc == -ERESTARTSYS )
74 int mdc_create(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
75 struct inode *dir, const char *name, int namelen,
76 const char *tgt, int tgtlen, int mode, __u64 id, __u32 uid,
77 __u32 gid, __u64 time, struct ptlrpc_request **request)
79 struct mds_rec_create *rec;
80 struct ptlrpc_request *req;
81 int rc, size[3] = {sizeof(*rec), namelen + 1, tgtlen + 1};
86 req = ptlrpc_prep_req(cl, conn, MDS_REINT, 3, size, NULL);
90 rec = lustre_msg_buf(req->rq_reqmsg, 0);
91 mds_create_pack(rec, dir, mode, id, uid, gid, time);
93 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
94 LOGL0(name, namelen, tmp);
97 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
98 LOGL0(tgt, tgtlen, tmp);
101 size[0] = sizeof(struct mds_body);
102 req->rq_replen = lustre_msg_size(1, size);
104 level = LUSTRE_CONN_FULL;
106 rc = mdc_reint(cl, req, level);
107 if (rc == -ERESTARTSYS) {
108 struct mds_update_record_hdr *hdr =
109 lustre_msg_buf(req->rq_reqmsg, 0);
110 level = LUSTRE_CONN_RECOVD;
111 CERROR("Lost reply: re-create rep.\n");
113 hdr->ur_opcode = NTOH__u32(REINT_RECREATE);
121 int mdc_unlink(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
122 struct inode *dir, struct inode *child, const char *name,
123 int namelen, struct ptlrpc_request **request)
125 struct mds_rec_unlink *rec;
126 struct ptlrpc_request *req;
127 int rc, size[2] = {sizeof(*rec), namelen + 1};
131 req = ptlrpc_prep_req(cl, conn, MDS_REINT, 2, size, NULL);
135 rec = lustre_msg_buf(req->rq_reqmsg, 0);
136 mds_unlink_pack(rec, dir, child);
138 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
139 LOGL0(name, namelen, tmp);
141 size[0] = sizeof(struct mds_body);
142 req->rq_replen = lustre_msg_size(1, size);
144 rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
146 if (rc == -ERESTARTSYS )
152 int mdc_link(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
153 struct dentry *src, struct inode *dir, const char *name,
154 int namelen, struct ptlrpc_request **request)
156 struct mds_rec_link *rec;
157 struct ptlrpc_request *req;
158 int rc, size[2] = {sizeof(*rec), namelen + 1};
162 req = ptlrpc_prep_req(cl, conn, MDS_REINT, 2, size, NULL);
166 rec = lustre_msg_buf(req->rq_reqmsg, 0);
167 mds_link_pack(rec, src->d_inode, dir);
169 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
170 LOGL0(name, namelen, tmp);
172 size[0] = sizeof(struct mds_body);
173 req->rq_replen = lustre_msg_size(1, size);
175 rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
177 if (rc == -ERESTARTSYS )
183 int mdc_rename(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
184 struct inode *src, struct inode *tgt, const char *old,
185 int oldlen, const char *new, int newlen,
186 struct ptlrpc_request **request)
188 struct mds_rec_rename *rec;
189 struct ptlrpc_request *req;
190 int rc, size[3] = {sizeof(*rec), oldlen + 1, newlen + 1};
194 req = ptlrpc_prep_req(cl, conn, MDS_REINT, 3, size, NULL);
198 rec = lustre_msg_buf(req->rq_reqmsg, 0);
199 mds_rename_pack(rec, src, tgt);
201 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
202 LOGL0(old, oldlen, tmp);
205 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
206 LOGL0(new, newlen, tmp);
209 size[0] = sizeof(struct mds_body);
210 req->rq_replen = lustre_msg_size(1, size);
212 rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
214 if (rc == -ERESTARTSYS )