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);
43 CERROR("error in handling %d\n", rc);
48 int mdc_setattr(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
49 struct inode *inode, struct iattr *iattr,
50 struct ptlrpc_request **request)
52 struct mds_rec_setattr *rec;
53 struct ptlrpc_request *req;
54 int rc, size = sizeof(*rec);
57 req = ptlrpc_prep_req(cl, conn, MDS_REINT, 1, &size, NULL);
61 rec = lustre_msg_buf(req->rq_reqmsg, 0);
62 mds_setattr_pack(rec, inode, iattr);
64 size = sizeof(struct mds_body);
65 req->rq_replen = lustre_msg_size(1, &size);
67 rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
69 if (rc == -ERESTARTSYS )
75 int mdc_create(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
76 struct inode *dir, const char *name, int namelen,
77 const char *tgt, int tgtlen, int mode, __u64 id, __u32 uid,
78 __u32 gid, __u64 time, struct ptlrpc_request **request)
80 struct mds_rec_create *rec;
81 struct ptlrpc_request *req;
82 int rc, size[3] = {sizeof(*rec), namelen + 1, tgtlen + 1};
87 req = ptlrpc_prep_req(cl, conn, MDS_REINT, 3, size, NULL);
91 rec = lustre_msg_buf(req->rq_reqmsg, 0);
92 mds_create_pack(rec, dir, mode, id, uid, gid, time);
94 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
95 LOGL0(name, namelen, tmp);
98 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
99 LOGL0(tgt, tgtlen, tmp);
102 size[0] = sizeof(struct mds_body);
103 req->rq_replen = lustre_msg_size(1, size);
105 level = LUSTRE_CONN_FULL;
107 rc = mdc_reint(cl, req, level);
108 if (rc == -ERESTARTSYS) {
109 struct mds_update_record_hdr *hdr =
110 lustre_msg_buf(req->rq_reqmsg, 0);
111 level = LUSTRE_CONN_RECOVD;
112 CERROR("Lost reply: re-create rep.\n");
114 hdr->ur_opcode = NTOH__u32(REINT_RECREATE);
122 int mdc_unlink(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
123 struct inode *dir, struct inode *child, const char *name,
124 int namelen, struct ptlrpc_request **request)
126 struct mds_rec_unlink *rec;
127 struct ptlrpc_request *req;
128 int rc, size[2] = {sizeof(*rec), namelen + 1};
132 req = ptlrpc_prep_req(cl, conn, MDS_REINT, 2, size, NULL);
136 rec = lustre_msg_buf(req->rq_reqmsg, 0);
137 mds_unlink_pack(rec, dir, child);
139 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
140 LOGL0(name, namelen, tmp);
142 size[0] = sizeof(struct mds_body);
143 req->rq_replen = lustre_msg_size(1, size);
145 rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
147 if (rc == -ERESTARTSYS )
153 int mdc_link(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
154 struct dentry *src, struct inode *dir, const char *name,
155 int namelen, struct ptlrpc_request **request)
157 struct mds_rec_link *rec;
158 struct ptlrpc_request *req;
159 int rc, size[2] = {sizeof(*rec), namelen + 1};
163 req = ptlrpc_prep_req(cl, conn, MDS_REINT, 2, size, NULL);
167 rec = lustre_msg_buf(req->rq_reqmsg, 0);
168 mds_link_pack(rec, src->d_inode, dir);
170 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
171 LOGL0(name, namelen, tmp);
173 size[0] = sizeof(struct mds_body);
174 req->rq_replen = lustre_msg_size(1, size);
176 rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
178 if (rc == -ERESTARTSYS )
184 int mdc_rename(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
185 struct inode *src, struct inode *tgt, const char *old,
186 int oldlen, const char *new, int newlen,
187 struct ptlrpc_request **request)
189 struct mds_rec_rename *rec;
190 struct ptlrpc_request *req;
191 int rc, size[3] = {sizeof(*rec), oldlen + 1, newlen + 1};
195 req = ptlrpc_prep_req(cl, conn, MDS_REINT, 3, size, NULL);
199 rec = lustre_msg_buf(req->rq_reqmsg, 0);
200 mds_rename_pack(rec, src, tgt);
202 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
203 LOGL0(old, oldlen, tmp);
206 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
207 LOGL0(new, newlen, tmp);
210 size[0] = sizeof(struct mds_body);
211 req->rq_replen = lustre_msg_size(1, size);
213 rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
215 if (rc == -ERESTARTSYS )