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 = lustre_msg_buf(req->rq_reqmsg, 0);
109 level = LUSTRE_CONN_RECOVD;
110 CERROR("Lost reply: re-create rep.\n");
112 hdr->ur_opcode = NTOH__u32(REINT_RECREATE);
120 int mdc_unlink(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
121 struct inode *dir, struct inode *child, const char *name,
122 int namelen, struct ptlrpc_request **request)
124 struct mds_rec_unlink *rec;
125 struct ptlrpc_request *req;
126 int rc, size[2] = {sizeof(*rec), namelen + 1};
130 req = ptlrpc_prep_req(cl, conn, MDS_REINT, 2, size, NULL);
134 rec = lustre_msg_buf(req->rq_reqmsg, 0);
135 mds_unlink_pack(rec, dir, child);
137 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
138 LOGL0(name, namelen, tmp);
140 size[0] = sizeof(struct mds_body);
141 req->rq_replen = lustre_msg_size(1, size);
143 rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
145 if (rc == -ERESTARTSYS )
151 int mdc_link(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
152 struct dentry *src, struct inode *dir, const char *name,
153 int namelen, struct ptlrpc_request **request)
155 struct mds_rec_link *rec;
156 struct ptlrpc_request *req;
157 int rc, size[2] = {sizeof(*rec), namelen + 1};
161 req = ptlrpc_prep_req(cl, conn, MDS_REINT, 2, size, NULL);
165 rec = lustre_msg_buf(req->rq_reqmsg, 0);
166 mds_link_pack(rec, src->d_inode, dir);
168 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
169 LOGL0(name, namelen, tmp);
171 size[0] = sizeof(struct mds_body);
172 req->rq_replen = lustre_msg_size(1, size);
174 rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
176 if (rc == -ERESTARTSYS )
182 int mdc_rename(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
183 struct inode *src, struct inode *tgt, const char *old,
184 int oldlen, const char *new, int newlen,
185 struct ptlrpc_request **request)
187 struct mds_rec_rename *rec;
188 struct ptlrpc_request *req;
189 int rc, size[3] = {sizeof(*rec), oldlen + 1, newlen + 1};
193 req = ptlrpc_prep_req(cl, conn, MDS_REINT, 3, size, NULL);
197 rec = lustre_msg_buf(req->rq_reqmsg, 0);
198 mds_rename_pack(rec, src, tgt);
200 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
201 LOGL0(old, oldlen, tmp);
204 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
205 LOGL0(new, newlen, tmp);
208 size[0] = sizeof(struct mds_body);
209 req->rq_replen = lustre_msg_size(1, size);
211 rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
213 if (rc == -ERESTARTSYS )