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 mdc_obd *mdc = mdc_conn2mdc(conn);
53 struct mds_rec_setattr *rec;
54 struct ptlrpc_request *req;
55 int rc, size = sizeof(*rec);
58 req = ptlrpc_prep_req2(mdc->mdc_client, mdc->mdc_conn, &mdc->mdc_connh,
59 MDS_REINT, 1, &size, NULL);
63 mds_setattr_pack(req, 0, inode, iattr, NULL, 0);
65 size = sizeof(struct mds_body);
66 req->rq_replen = lustre_msg_size(1, &size);
68 rc = mdc_reint(req, LUSTRE_CONN_FULL);
70 if (rc == -ERESTARTSYS )
76 int mdc_create(struct lustre_handle *conn,
77 struct inode *dir, const char *name, int namelen,
78 const char *tgt, int tgtlen, int mode, __u32 uid,
79 __u32 gid, __u64 time, __u64 rdev, struct lov_stripe_md *md,
80 struct ptlrpc_request **request)
82 struct mds_rec_create *rec;
83 struct mdc_obd *mdc = mdc_conn2mdc(conn);
84 struct ptlrpc_request *req;
85 int rc, size[3] = {sizeof(struct mds_rec_create), namelen + 1, 0};
86 char *tmp, *bufs[3] = {NULL, NULL, NULL};
87 int level, bufcount = 2;
92 CERROR("File create, but no md (%ld, %*s)\n",
93 dir->i_ino, namelen, name);
96 size[2] = md->lmd_size;
99 } else if (S_ISLNK(mode)) {
100 size[2] = tgtlen + 1;
104 req = ptlrpc_prep_req2(mdc->mdc_client, mdc->mdc_conn, &mdc->mdc_connh,
106 bufcount, size, bufs);
110 /* mds_create_pack fills bufs[1] with name */
111 rec = lustre_msg_buf(req->rq_reqmsg, 0);
112 mds_create_pack(req, 0, dir, mode, rdev, uid, gid, time,
113 name, namelen, NULL, 0);
116 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
117 memcpy(tmp, md, md->lmd_size);
118 } else if (S_ISLNK(mode)) {
119 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
120 LOGL0(tgt, tgtlen, tmp);
123 size[0] = sizeof(struct mds_body);
124 req->rq_replen = lustre_msg_size(1, size);
126 level = LUSTRE_CONN_FULL;
128 rc = mdc_reint(req, level);
129 if (rc == -ERESTARTSYS) {
130 struct mds_update_record_hdr *hdr =
131 lustre_msg_buf(req->rq_reqmsg, 0);
132 level = LUSTRE_CONN_RECOVD;
133 CERROR("Lost reply: re-create rep.\n");
135 hdr->ur_opcode = NTOH__u32(REINT_RECREATE);
143 int mdc_unlink(struct lustre_handle *conn,
144 struct inode *dir, struct inode *child, const char *name,
145 int namelen, struct ptlrpc_request **request)
147 struct mdc_obd *mdc = mdc_conn2mdc(conn);
148 struct ptlrpc_request *req;
149 int rc, size[2] = {sizeof(struct mds_rec_unlink), namelen + 1};
152 req = ptlrpc_prep_req2(mdc->mdc_client, mdc->mdc_conn, &mdc->mdc_connh,
153 MDS_REINT, 2, size, NULL);
157 mds_unlink_pack(req, 0, dir, child, name, namelen);
159 size[0] = sizeof(struct mds_body);
160 req->rq_replen = lustre_msg_size(1, size);
162 rc = mdc_reint(req, LUSTRE_CONN_FULL);
164 if (rc == -ERESTARTSYS )
170 int mdc_link(struct lustre_handle *conn,
171 struct dentry *src, struct inode *dir, const char *name,
172 int namelen, struct ptlrpc_request **request)
174 struct mdc_obd *mdc = mdc_conn2mdc(conn);
175 struct ptlrpc_request *req;
176 int rc, size[2] = {sizeof(struct mds_rec_link), namelen + 1};
179 req = ptlrpc_prep_req2(mdc->mdc_client, mdc->mdc_conn, &mdc->mdc_connh,
180 MDS_REINT, 2, size, NULL);
184 mds_link_pack(req, 0, src->d_inode, dir, name, namelen);
186 size[0] = sizeof(struct mds_body);
187 req->rq_replen = lustre_msg_size(1, size);
189 rc = mdc_reint(req, LUSTRE_CONN_FULL);
191 if (rc == -ERESTARTSYS )
197 int mdc_rename(struct lustre_handle *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 mdc_obd *mdc = mdc_conn2mdc(conn);
203 struct ptlrpc_request *req;
204 int rc, size[3] = {sizeof(struct mds_rec_rename), oldlen + 1,
208 req = ptlrpc_prep_req2(mdc->mdc_client, mdc->mdc_conn, &mdc->mdc_connh,
209 MDS_REINT, 3, size, NULL);
213 mds_rename_pack(req, 0, src, tgt, old, oldlen, new, newlen);
215 size[0] = sizeof(struct mds_body);
216 req->rq_replen = lustre_msg_size(1, size);
218 rc = mdc_reint(req, LUSTRE_CONN_FULL);
220 if (rc == -ERESTARTSYS )