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_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 lustre_handle *conn,
49 struct inode *inode, struct iattr *iattr,
50 struct ptlrpc_request **request)
52 struct ptlrpc_request *req;
53 struct mds_rec_setattr *rec;
54 int rc, size = sizeof(*rec);
57 req = ptlrpc_prep_req2(conn, MDS_REINT, 1, &size, NULL);
61 mds_setattr_pack(req, 0, inode, iattr, NULL, 0);
63 size = sizeof(struct mds_body);
64 req->rq_replen = lustre_msg_size(1, &size);
66 rc = mdc_reint(req, LUSTRE_CONN_FULL);
68 if (rc == -ERESTARTSYS )
74 int mdc_create(struct lustre_handle *conn,
75 struct inode *dir, const char *name, int namelen,
76 const char *tgt, int tgtlen, int mode, __u32 uid,
77 __u32 gid, __u64 time, __u64 rdev, struct lov_stripe_md *smd,
78 struct ptlrpc_request **request)
80 struct mds_rec_create *rec;
81 struct ptlrpc_request *req;
82 int rc, size[3] = {sizeof(struct mds_rec_create), namelen + 1, 0};
83 char *tmp, *bufs[3] = {NULL, NULL, NULL};
84 int level, bufcount = 2;
89 CERROR("File create, but no md (%ld, %*s)\n",
90 dir->i_ino, namelen, name);
93 size[2] = smd->lmd_easize;
94 bufs[2] = (char *)smd;
96 } else if (S_ISLNK(mode)) {
101 req = ptlrpc_prep_req2(conn, MDS_REINT, bufcount, size, bufs);
105 /* mds_create_pack fills bufs[1] with name */
106 rec = lustre_msg_buf(req->rq_reqmsg, 0);
107 mds_create_pack(req, 0, dir, mode, rdev, uid, gid, time,
108 name, namelen, NULL, 0);
111 lov_packmd(lustre_msg_buf(req->rq_reqmsg, 2), smd);
112 } else if (S_ISLNK(mode)) {
113 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
114 LOGL0(tgt, tgtlen, tmp);
117 size[0] = sizeof(struct mds_body);
118 req->rq_replen = lustre_msg_size(1, size);
120 level = LUSTRE_CONN_FULL;
122 rc = mdc_reint(req, level);
123 if (rc == -ERESTARTSYS) {
124 __u32 *opcode = lustre_msg_buf(req->rq_reqmsg, 0);
125 level = LUSTRE_CONN_RECOVD;
126 CERROR("Lost reply: re-create rep.\n");
128 *opcode = NTOH__u32(REINT_RECREATE);
136 int mdc_unlink(struct lustre_handle *conn, struct inode *dir,
137 struct inode *child, __u32 mode, const char *name, int namelen,
138 struct ptlrpc_request **request)
140 struct ptlrpc_request *req;
141 int rc, size[2] = {sizeof(struct mds_rec_unlink), namelen + 1};
144 req = ptlrpc_prep_req2(conn, MDS_REINT, 2, size, NULL);
148 mds_unlink_pack(req, 0, dir, child, mode, name, namelen);
150 size[0] = sizeof(struct mds_body);
151 req->rq_replen = lustre_msg_size(1, size);
153 rc = mdc_reint(req, LUSTRE_CONN_FULL);
155 if (rc == -ERESTARTSYS)
161 int mdc_link(struct lustre_handle *conn,
162 struct dentry *src, struct inode *dir, const char *name,
163 int namelen, struct ptlrpc_request **request)
165 struct ptlrpc_request *req;
166 int rc, size[2] = {sizeof(struct mds_rec_link), namelen + 1};
169 req = ptlrpc_prep_req2(conn, MDS_REINT, 2, size, NULL);
173 mds_link_pack(req, 0, src->d_inode, dir, name, namelen);
175 size[0] = sizeof(struct mds_body);
176 req->rq_replen = lustre_msg_size(1, size);
178 rc = mdc_reint(req, LUSTRE_CONN_FULL);
180 if (rc == -ERESTARTSYS )
186 int mdc_rename(struct lustre_handle *conn,
187 struct inode *src, struct inode *tgt, const char *old,
188 int oldlen, const char *new, int newlen,
189 struct ptlrpc_request **request)
191 struct ptlrpc_request *req;
192 int rc, size[3] = {sizeof(struct mds_rec_rename), oldlen + 1,
196 req = ptlrpc_prep_req2(conn, MDS_REINT, 3, size, NULL);
200 mds_rename_pack(req, 0, src, tgt, old, oldlen, new, newlen);
202 size[0] = sizeof(struct mds_body);
203 req->rq_replen = lustre_msg_size(1, size);
205 rc = mdc_reint(req, LUSTRE_CONN_FULL);
207 if (rc == -ERESTARTSYS )