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, __u32 uid,
78 __u32 gid, __u64 time, __u64 rdev, struct obdo *obdo,
79 struct ptlrpc_request **request)
81 struct mds_rec_create *rec;
82 struct ptlrpc_request *req;
83 int rc, size[3] = {sizeof(*rec), namelen + 1, 0};
84 char *tmp, *bufs[3] = {NULL, NULL, NULL};
85 int level, bufcount = 2;
89 size[2] = sizeof(*obdo);
90 bufs[2] = (char *)obdo;
92 } else if (S_ISLNK(mode)) {
97 req = ptlrpc_prep_req(cl, conn, MDS_REINT, bufcount, size, bufs);
101 rec = lustre_msg_buf(req->rq_reqmsg, 0);
102 mds_create_pack(rec, dir, mode, rdev, uid, gid, time);
104 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
105 LOGL0(name, namelen, tmp);
108 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
109 memcpy(tmp, obdo, sizeof(*obdo));
110 } else if (S_ISLNK(mode)) {
111 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
112 LOGL0(tgt, tgtlen, tmp);
115 size[0] = sizeof(struct mds_body);
116 req->rq_replen = lustre_msg_size(1, size);
118 level = LUSTRE_CONN_FULL;
120 rc = mdc_reint(cl, req, level);
121 if (rc == -ERESTARTSYS) {
122 struct mds_update_record_hdr *hdr =
123 lustre_msg_buf(req->rq_reqmsg, 0);
124 level = LUSTRE_CONN_RECOVD;
125 CERROR("Lost reply: re-create rep.\n");
127 hdr->ur_opcode = NTOH__u32(REINT_RECREATE);
135 int mdc_unlink(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
136 struct inode *dir, struct inode *child, const char *name,
137 int namelen, struct ptlrpc_request **request)
139 struct mds_rec_unlink *rec;
140 struct ptlrpc_request *req;
141 int rc, size[2] = {sizeof(*rec), namelen + 1};
145 req = ptlrpc_prep_req(cl, conn, MDS_REINT, 2, size, NULL);
149 rec = lustre_msg_buf(req->rq_reqmsg, 0);
150 mds_unlink_pack(rec, dir, child);
152 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
153 LOGL0(name, namelen, tmp);
155 size[0] = sizeof(struct mds_body);
156 req->rq_replen = lustre_msg_size(1, size);
158 rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
160 if (rc == -ERESTARTSYS )
166 int mdc_link(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
167 struct dentry *src, struct inode *dir, const char *name,
168 int namelen, struct ptlrpc_request **request)
170 struct mds_rec_link *rec;
171 struct ptlrpc_request *req;
172 int rc, size[2] = {sizeof(*rec), namelen + 1};
176 req = ptlrpc_prep_req(cl, conn, MDS_REINT, 2, size, NULL);
180 rec = lustre_msg_buf(req->rq_reqmsg, 0);
181 mds_link_pack(rec, src->d_inode, dir);
183 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
184 LOGL0(name, namelen, tmp);
186 size[0] = sizeof(struct mds_body);
187 req->rq_replen = lustre_msg_size(1, size);
189 rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
191 if (rc == -ERESTARTSYS )
197 int mdc_rename(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
198 struct inode *src, struct inode *tgt, const char *old,
199 int oldlen, const char *new, int newlen,
200 struct ptlrpc_request **request)
202 struct mds_rec_rename *rec;
203 struct ptlrpc_request *req;
204 int rc, size[3] = {sizeof(*rec), oldlen + 1, newlen + 1};
208 req = ptlrpc_prep_req(cl, conn, MDS_REINT, 3, size, NULL);
212 rec = lustre_msg_buf(req->rq_reqmsg, 0);
213 mds_rename_pack(rec, src, tgt);
215 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
216 LOGL0(old, oldlen, tmp);
219 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
220 LOGL0(new, newlen, tmp);
223 size[0] = sizeof(struct mds_body);
224 req->rq_replen = lustre_msg_size(1, size);
226 rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
228 if (rc == -ERESTARTSYS )