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 Portals, http://www.sf.net/projects/lustre/
8 * Portals 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 * Portals 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 Portals; 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 #include <linux/string.h>
30 #include <linux/stat.h>
31 #include <linux/errno.h>
32 #include <linux/locks.h>
33 #include <linux/unistd.h>
35 #include <asm/system.h>
36 #include <asm/uaccess.h>
37 #include <linux/module.h>
40 #include <linux/stat.h>
41 #include <asm/uaccess.h>
42 #include <asm/segment.h>
43 #include <linux/miscdevice.h>
45 #define DEBUG_SUBSYSTEM S_MDC
47 #include <linux/obd_support.h>
48 #include <linux/lustre_lib.h>
49 #include <linux/lustre_idl.h>
50 #include <linux/lustre_mds.h>
52 extern int mdc_reint(struct lustre_peer *peer, struct ptlrpc_request *request);
53 extern struct ptlrpc_request *mds_prep_req(int opcode, int namelen, char *name,
54 int tgtlen, char *tgt);
56 int mdc_setattr(struct lustre_peer *peer,
57 struct inode *inode, struct iattr *iattr,
58 struct mds_rep **rep, struct ptlrep_hdr **hdr)
61 struct ptlrpc_request *request;
62 struct mds_rec_setattr *rec;
64 request = mds_prep_req(MDS_REINT, 0, NULL, sizeof(*rec), NULL);
66 CERROR("mdc request: cannot pack\n");
70 rec = mds_req_tgt(request->rq_req.mds);
71 mds_setattr_pack(rec, inode, iattr);
72 request->rq_req.mds->opcode = HTON__u32(REINT_SETATTR);
74 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
76 rc = mdc_reint(peer, request);
81 *rep = request->rq_rep.mds;
84 *hdr = request->rq_rephdr;
90 int mdc_create(struct lustre_peer *peer,
91 struct inode *dir, const char *name, int namelen,
92 const char *tgt, int tgtlen,
93 int mode, __u64 id, __u32 uid, __u32 gid, __u64 time,
94 struct mds_rep **rep, struct ptlrep_hdr **hdr)
97 struct ptlrpc_request *request;
98 struct mds_rec_create *rec;
100 request = mds_prep_req(MDS_REINT, 0, NULL,
101 sizeof(*rec) + size_round0(namelen) +
102 size_round0(tgtlen), NULL);
104 CERROR("mdc_create: cannot pack\n");
109 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
111 rec = mds_req_tgt(request->rq_req.mds);
112 mds_create_pack(rec, dir, name, namelen, mode, id, uid, gid, time,
115 rc = mdc_reint(peer, request);
118 *rep = request->rq_rep.mds;
121 *hdr = request->rq_rephdr;
124 OBD_FREE(request, sizeof(*request));
128 int mdc_unlink(struct lustre_peer *peer,
129 struct inode *dir, const char *name, int namelen,
130 struct mds_rep **rep, struct ptlrep_hdr **hdr)
133 struct ptlrpc_request *request;
134 struct mds_rec_unlink *rec;
136 request = mds_prep_req(MDS_REINT, 0, NULL,
137 sizeof(*rec) + size_round0(namelen), NULL);
139 CERROR("mdc_unlink: cannot pack\n");
144 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
146 rec = mds_req_tgt(request->rq_req.mds);
147 mds_unlink_pack(rec, dir, name, namelen);
149 rc = mdc_reint(peer, request);
152 *rep = request->rq_rep.mds;
155 *hdr = request->rq_rephdr;
158 OBD_FREE(request, sizeof(*request));
162 int mdc_link(struct lustre_peer *peer, struct dentry *src,
163 struct inode *dir, const char *name, int namelen,
164 struct mds_rep **rep, struct ptlrep_hdr **hdr)
167 struct ptlrpc_request *request;
168 struct mds_rec_link *rec;
170 request = mds_prep_req(MDS_REINT, 0, NULL,
171 sizeof(*rec) + size_round0(namelen), NULL);
173 CERROR("mdc_link: cannot pack\n");
178 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
180 rec = mds_req_tgt(request->rq_req.mds);
181 mds_link_pack(rec, src->d_inode, dir, name, namelen);
183 rc = mdc_reint(peer, request);
186 *rep = request->rq_rep.mds;
189 *hdr = request->rq_rephdr;
192 OBD_FREE(request, sizeof(*request));
196 int mdc_rename(struct lustre_peer *peer, struct inode *src,
197 struct inode *tgt, const char *old, int oldlen,
198 const char *new, int newlen,
199 struct mds_rep **rep, struct ptlrep_hdr **hdr)
202 struct ptlrpc_request *request;
203 struct mds_rec_rename *rec;
205 request = mds_prep_req(MDS_REINT, 0, NULL,
206 sizeof(*rec) + size_round0(oldlen)
207 + size_round0(newlen), NULL);
209 CERROR("mdc_link: cannot pack\n");
214 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
216 rec = mds_req_tgt(request->rq_req.mds);
217 mds_rename_pack(rec, src, tgt, old, oldlen, new, newlen);
219 rc = mdc_reint(peer, request);
222 *rep = request->rq_rep.mds;
225 *hdr = request->rq_rephdr;
228 OBD_FREE(request, sizeof(*request));