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 ptlrpc_client *peer, struct ptlrpc_request *request);
54 int mdc_setattr(struct ptlrpc_client *peer,
55 struct inode *inode, struct iattr *iattr,
56 struct mds_rep **rep, struct ptlrep_hdr **hdr)
59 struct ptlrpc_request *request;
60 struct mds_rec_setattr *rec;
62 request = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL, sizeof(*rec), NULL);
64 CERROR("mdc request: cannot pack\n");
68 rec = mds_req_tgt(request->rq_req.mds);
69 mds_setattr_pack(rec, inode, iattr);
70 request->rq_req.mds->opcode = HTON__u32(REINT_SETATTR);
72 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
74 rc = mdc_reint(peer, request);
79 *rep = request->rq_rep.mds;
82 *hdr = request->rq_rephdr;
88 int mdc_create(struct ptlrpc_client *peer,
89 struct inode *dir, const char *name, int namelen,
90 const char *tgt, int tgtlen,
91 int mode, __u64 id, __u32 uid, __u32 gid, __u64 time,
92 struct mds_rep **rep, struct ptlrep_hdr **hdr)
95 struct ptlrpc_request *request;
96 struct mds_rec_create *rec;
98 request = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL,
99 sizeof(*rec) + size_round0(namelen) +
100 size_round0(tgtlen), NULL);
102 CERROR("mdc_create: cannot pack\n");
107 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
109 rec = mds_req_tgt(request->rq_req.mds);
110 mds_create_pack(rec, dir, name, namelen, mode, id, uid, gid, time,
113 rc = mdc_reint(peer, request);
116 *rep = request->rq_rep.mds;
119 *hdr = request->rq_rephdr;
122 OBD_FREE(request, sizeof(*request));
126 int mdc_unlink(struct ptlrpc_client *peer,
127 struct inode *dir, const char *name, int namelen,
128 struct mds_rep **rep, struct ptlrep_hdr **hdr)
131 struct ptlrpc_request *request;
132 struct mds_rec_unlink *rec;
134 request = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL,
135 sizeof(*rec) + size_round0(namelen), NULL);
137 CERROR("mdc_unlink: cannot pack\n");
142 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
144 rec = mds_req_tgt(request->rq_req.mds);
145 mds_unlink_pack(rec, dir, name, namelen);
147 rc = mdc_reint(peer, request);
150 *rep = request->rq_rep.mds;
153 *hdr = request->rq_rephdr;
156 OBD_FREE(request, sizeof(*request));
160 int mdc_link(struct ptlrpc_client *peer, struct dentry *src,
161 struct inode *dir, const char *name, int namelen,
162 struct mds_rep **rep, struct ptlrep_hdr **hdr)
165 struct ptlrpc_request *request;
166 struct mds_rec_link *rec;
168 request = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL,
169 sizeof(*rec) + size_round0(namelen), NULL);
171 CERROR("mdc_link: cannot pack\n");
176 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
178 rec = mds_req_tgt(request->rq_req.mds);
179 mds_link_pack(rec, src->d_inode, dir, name, namelen);
181 rc = mdc_reint(peer, request);
184 *rep = request->rq_rep.mds;
187 *hdr = request->rq_rephdr;
190 OBD_FREE(request, sizeof(*request));
194 int mdc_rename(struct ptlrpc_client *peer, struct inode *src,
195 struct inode *tgt, const char *old, int oldlen,
196 const char *new, int newlen,
197 struct mds_rep **rep, struct ptlrep_hdr **hdr)
200 struct ptlrpc_request *request;
201 struct mds_rec_rename *rec;
203 request = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL,
204 sizeof(*rec) + size_round0(oldlen)
205 + size_round0(newlen), NULL);
207 CERROR("mdc_link: cannot pack\n");
212 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
214 rec = mds_req_tgt(request->rq_req.mds);
215 mds_rename_pack(rec, src, tgt, old, oldlen, new, newlen);
217 rc = mdc_reint(peer, request);
220 *rep = request->rq_rep.mds;
223 *hdr = request->rq_rephdr;
226 OBD_FREE(request, sizeof(*request));