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/obd_class.h>
49 #include <linux/lustre_lib.h>
50 #include <linux/lustre_idl.h>
51 #include <linux/lustre_mds.h>
53 extern int mdc_reint(struct ptlrpc_client *peer, struct ptlrpc_request *request);
55 int mdc_setattr(struct ptlrpc_client *peer,
56 struct inode *inode, struct iattr *iattr,
57 struct mds_rep **rep, struct ptlrep_hdr **hdr)
60 struct ptlrpc_request *request;
61 struct mds_rec_setattr *rec;
63 request = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL, sizeof(*rec), NULL);
65 CERROR("mdc request: cannot pack\n");
69 rec = mds_req_tgt(request->rq_req.mds);
70 mds_setattr_pack(rec, inode, iattr);
71 request->rq_req.mds->opcode = HTON__u32(REINT_SETATTR);
73 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
75 rc = mdc_reint(peer, request);
80 *rep = request->rq_rep.mds;
83 *hdr = request->rq_rephdr;
89 int mdc_create(struct ptlrpc_client *peer,
90 struct inode *dir, const char *name, int namelen,
91 const char *tgt, int tgtlen,
92 int mode, __u64 id, __u32 uid, __u32 gid, __u64 time,
93 struct mds_rep **rep, struct ptlrep_hdr **hdr)
96 struct ptlrpc_request *request;
97 struct mds_rec_create *rec;
99 request = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL,
100 sizeof(*rec) + size_round0(namelen) +
101 size_round0(tgtlen), NULL);
103 CERROR("mdc_create: cannot pack\n");
108 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
110 rec = mds_req_tgt(request->rq_req.mds);
111 mds_create_pack(rec, dir, name, namelen, mode, id, uid, gid, time,
114 rc = mdc_reint(peer, request);
117 *rep = request->rq_rep.mds;
120 *hdr = request->rq_rephdr;
123 OBD_FREE(request, sizeof(*request));
127 int mdc_unlink(struct ptlrpc_client *peer,
128 struct inode *dir, const char *name, int namelen,
129 struct mds_rep **rep, struct ptlrep_hdr **hdr)
132 struct ptlrpc_request *request;
133 struct mds_rec_unlink *rec;
135 request = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL,
136 sizeof(*rec) + size_round0(namelen), NULL);
138 CERROR("mdc_unlink: cannot pack\n");
143 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
145 rec = mds_req_tgt(request->rq_req.mds);
146 mds_unlink_pack(rec, dir, name, namelen);
148 rc = mdc_reint(peer, request);
151 *rep = request->rq_rep.mds;
154 *hdr = request->rq_rephdr;
157 OBD_FREE(request, sizeof(*request));
161 int mdc_link(struct ptlrpc_client *peer, struct dentry *src,
162 struct inode *dir, const char *name, int namelen,
163 struct mds_rep **rep, struct ptlrep_hdr **hdr)
166 struct ptlrpc_request *request;
167 struct mds_rec_link *rec;
169 request = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL,
170 sizeof(*rec) + size_round0(namelen), NULL);
172 CERROR("mdc_link: cannot pack\n");
177 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
179 rec = mds_req_tgt(request->rq_req.mds);
180 mds_link_pack(rec, src->d_inode, dir, name, namelen);
182 rc = mdc_reint(peer, request);
185 *rep = request->rq_rep.mds;
188 *hdr = request->rq_rephdr;
191 OBD_FREE(request, sizeof(*request));
195 int mdc_rename(struct ptlrpc_client *peer, struct inode *src,
196 struct inode *tgt, const char *old, int oldlen,
197 const char *new, int newlen,
198 struct mds_rep **rep, struct ptlrep_hdr **hdr)
201 struct ptlrpc_request *request;
202 struct mds_rec_rename *rec;
204 request = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL,
205 sizeof(*rec) + size_round0(oldlen)
206 + size_round0(newlen), NULL);
208 CERROR("mdc_link: cannot pack\n");
213 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
215 rec = mds_req_tgt(request->rq_req.mds);
216 mds_rename_pack(rec, src, tgt, old, oldlen, new, newlen);
218 rc = mdc_reint(peer, request);
221 *rep = request->rq_rep.mds;
224 *hdr = request->rq_rephdr;
227 OBD_FREE(request, sizeof(*request));