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)
38 rc = ptlrpc_queue_wait(request);
39 rc = ptlrpc_check_status(request, rc);
41 CERROR("error in handling %d\n", rc);
46 int mdc_setattr(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
47 struct inode *inode, struct iattr *iattr,
48 struct ptlrpc_request **request)
50 struct mds_rec_setattr *rec;
51 struct ptlrpc_request *req;
52 int rc, size = sizeof(*rec);
55 req = ptlrpc_prep_req(cl, conn, MDS_REINT, 1, &size, NULL);
59 rec = lustre_msg_buf(req->rq_reqmsg, 0);
60 mds_setattr_pack(rec, inode, iattr);
62 size = sizeof(struct mds_body);
63 req->rq_replen = lustre_msg_size(1, &size);
65 rc = mdc_reint(cl, req);
71 int mdc_create(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
72 struct inode *dir, const char *name, int namelen,
73 const char *tgt, int tgtlen, int mode, __u64 id, __u32 uid,
74 __u32 gid, __u64 time, struct ptlrpc_request **request)
76 struct mds_rec_create *rec;
77 struct ptlrpc_request *req;
78 int rc, size[3] = {sizeof(*rec), namelen + 1, tgtlen + 1};
82 req = ptlrpc_prep_req(cl, conn, MDS_REINT, 3, size, NULL);
86 rec = lustre_msg_buf(req->rq_reqmsg, 0);
87 mds_create_pack(rec, dir, mode, id, uid, gid, time);
89 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
90 LOGL0(name, namelen, tmp);
93 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
94 LOGL0(tgt, tgtlen, tmp);
97 size[0] = sizeof(struct mds_body);
98 req->rq_replen = lustre_msg_size(1, size);
100 rc = mdc_reint(cl, req);
106 int mdc_unlink(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
107 struct inode *dir, struct inode *child, const char *name,
108 int namelen, struct ptlrpc_request **request)
110 struct mds_rec_unlink *rec;
111 struct ptlrpc_request *req;
112 int rc, size[2] = {sizeof(*rec), namelen + 1};
116 req = ptlrpc_prep_req(cl, conn, MDS_REINT, 2, size, NULL);
120 rec = lustre_msg_buf(req->rq_reqmsg, 0);
121 mds_unlink_pack(rec, dir, child);
123 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
124 LOGL0(name, namelen, tmp);
126 size[0] = sizeof(struct mds_body);
127 req->rq_replen = lustre_msg_size(1, size);
129 rc = mdc_reint(cl, req);
135 int mdc_link(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
136 struct dentry *src, struct inode *dir, const char *name,
137 int namelen, struct ptlrpc_request **request)
139 struct mds_rec_link *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_link_pack(rec, src->d_inode, dir);
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);
164 int mdc_rename(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
165 struct inode *src, struct inode *tgt, const char *old,
166 int oldlen, const char *new, int newlen,
167 struct ptlrpc_request **request)
169 struct mds_rec_rename *rec;
170 struct ptlrpc_request *req;
171 int rc, size[3] = {sizeof(*rec), oldlen + 1, newlen + 1};
175 req = ptlrpc_prep_req(cl, conn, MDS_REINT, 3, size, NULL);
179 rec = lustre_msg_buf(req->rq_reqmsg, 0);
180 mds_rename_pack(rec, src, tgt);
182 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
183 LOGL0(old, oldlen, tmp);
186 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
187 LOGL0(new, newlen, tmp);
190 size[0] = sizeof(struct mds_body);
191 req->rq_replen = lustre_msg_size(1, size);
193 rc = mdc_reint(cl, req);