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(cl, 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 inode *inode,
47 struct iattr *iattr, struct ptlrpc_request **request)
49 struct mds_rec_setattr *rec;
50 struct ptlrpc_request *req;
51 int rc, size = sizeof(*rec);
54 req = ptlrpc_prep_req(cl, MDS_REINT, 1, &size, NULL);
58 rec = lustre_msg_buf(req->rq_reqmsg, 0);
59 mds_setattr_pack(rec, inode, iattr);
61 size = sizeof(struct mds_body);
62 req->rq_replen = lustre_msg_size(1, &size);
64 rc = mdc_reint(cl, req);
70 int mdc_create(struct ptlrpc_client *cl, struct inode *dir, const char *name,
71 int namelen, const char *tgt, int tgtlen, int mode, __u64 id,
72 __u32 uid, __u32 gid, __u64 time,
73 struct ptlrpc_request **request)
75 struct mds_rec_create *rec;
76 struct ptlrpc_request *req;
77 int rc, size[3] = {sizeof(*rec), namelen + 1, tgtlen + 1};
81 req = ptlrpc_prep_req(cl, MDS_REINT, 3, size, NULL);
85 rec = lustre_msg_buf(req->rq_reqmsg, 0);
86 mds_create_pack(rec, dir, mode, id, uid, gid, time);
88 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
89 LOGL0(name, namelen, tmp);
92 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
93 LOGL0(tgt, tgtlen, tmp);
96 size[0] = sizeof(struct mds_body);
97 req->rq_replen = lustre_msg_size(1, size);
99 rc = mdc_reint(cl, req);
105 int mdc_unlink(struct ptlrpc_client *cl, struct inode *dir,
106 struct inode *child, const char *name, int namelen,
107 struct ptlrpc_request **request)
109 struct mds_rec_unlink *rec;
110 struct ptlrpc_request *req;
111 int rc, size[2] = {sizeof(*rec), namelen + 1};
115 req = ptlrpc_prep_req(cl, MDS_REINT, 2, size, NULL);
119 rec = lustre_msg_buf(req->rq_reqmsg, 0);
120 mds_unlink_pack(rec, dir, child);
122 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
123 LOGL0(name, namelen, tmp);
125 size[0] = sizeof(struct mds_body);
126 req->rq_replen = lustre_msg_size(1, size);
128 rc = mdc_reint(cl, req);
134 int mdc_link(struct ptlrpc_client *cl, struct dentry *src, struct inode *dir,
135 const char *name, int namelen, struct ptlrpc_request **request)
137 struct mds_rec_link *rec;
138 struct ptlrpc_request *req;
139 int rc, size[2] = {sizeof(*rec), namelen + 1};
143 req = ptlrpc_prep_req(cl, MDS_REINT, 2, size, NULL);
147 rec = lustre_msg_buf(req->rq_reqmsg, 0);
148 mds_link_pack(rec, src->d_inode, dir);
150 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
151 LOGL0(name, namelen, tmp);
153 size[0] = sizeof(struct mds_body);
154 req->rq_replen = lustre_msg_size(1, size);
156 rc = mdc_reint(cl, req);
162 int mdc_rename(struct ptlrpc_client *cl, struct inode *src, struct inode *tgt,
163 const char *old, int oldlen, const char *new, int newlen,
164 struct ptlrpc_request **request)
166 struct mds_rec_rename *rec;
167 struct ptlrpc_request *req;
168 int rc, size[3] = {sizeof(*rec), oldlen + 1, newlen + 1};
172 req = ptlrpc_prep_req(cl, MDS_REINT, 3, size, NULL);
176 rec = lustre_msg_buf(req->rq_reqmsg, 0);
177 mds_rename_pack(rec, src, tgt);
179 tmp = lustre_msg_buf(req->rq_reqmsg, 1);
180 LOGL0(old, oldlen, tmp);
183 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
184 LOGL0(new, newlen, tmp);
187 size[0] = sizeof(struct mds_body);
188 req->rq_replen = lustre_msg_size(1, size);
190 rc = mdc_reint(cl, req);