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);
40 CERROR("error in handling %d\n", rc);
45 int mdc_setattr(struct ptlrpc_client *peer,
46 struct inode *inode, struct iattr *iattr,
47 struct ptlrpc_request **request)
50 struct mds_rec_setattr *rec;
53 *request = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL,
56 CERROR("cannot pack\n");
61 rec = mds_req_tgt((*request)->rq_req.mds);
62 mds_setattr_pack(rec, inode, iattr);
63 (*request)->rq_req.mds->opcode = HTON__u32(REINT_SETATTR);
64 (*request)->rq_replen =
65 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
67 rc = mdc_reint(peer, *request);
73 int mdc_create(struct ptlrpc_client *peer,
74 struct inode *dir, const char *name, int namelen,
75 const char *tgt, int tgtlen,
76 int mode, __u64 id, __u32 uid, __u32 gid, __u64 time,
77 struct ptlrpc_request **request)
80 struct mds_rec_create *rec;
83 (*request) = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL,
84 sizeof(*rec) + size_round0(namelen) +
85 size_round0(tgtlen), NULL);
87 CERROR("cannot pack\n");
91 (*request)->rq_replen =
92 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
94 rec = mds_req_tgt((*request)->rq_req.mds);
95 mds_create_pack(rec, dir, name, namelen, mode, id, uid, gid, time,
98 rc = mdc_reint(peer, (*request));
104 int mdc_unlink(struct ptlrpc_client *peer, struct inode *dir,
105 struct inode *child, const char *name, int namelen,
106 struct ptlrpc_request **request)
109 struct mds_rec_unlink *rec;
111 (*request) = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL,
112 sizeof(*rec) + size_round0(namelen), NULL);
114 CERROR("cannot pack\n");
118 (*request)->rq_replen =
119 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
121 rec = mds_req_tgt((*request)->rq_req.mds);
122 mds_unlink_pack(rec, dir, child, name, namelen);
124 rc = mdc_reint(peer, (*request));
130 int mdc_link(struct ptlrpc_client *peer, struct dentry *src,
131 struct inode *dir, const char *name, int namelen,
132 struct ptlrpc_request **request)
135 struct mds_rec_link *rec;
138 (*request) = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL,
139 sizeof(*rec) + size_round0(namelen), NULL);
141 CERROR("cannot pack\n");
145 (*request)->rq_replen =
146 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
148 rec = mds_req_tgt((*request)->rq_req.mds);
149 mds_link_pack(rec, src->d_inode, dir, name, namelen);
151 rc = mdc_reint(peer, (*request));
156 int mdc_rename(struct ptlrpc_client *peer, struct inode *src,
157 struct inode *tgt, const char *old, int oldlen,
158 const char *new, int newlen,
159 struct ptlrpc_request **request)
162 struct mds_rec_rename *rec;
165 (*request) = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL,
166 sizeof(*rec) + size_round0(oldlen)
167 + size_round0(newlen), NULL);
169 CERROR("cannot pack\n");
173 (*request)->rq_replen =
174 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
176 rec = mds_req_tgt((*request)->rq_req.mds);
177 mds_rename_pack(rec, src, tgt, old, oldlen, new, newlen);
179 rc = mdc_reint(peer, (*request));