Whamcloud - gitweb
- fixed up lustre_mds.h to allow inclusion in userspace testreq.c
[fs/lustre-release.git] / lustre / mdc / mdc_reint.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.sf.net/projects/lustre/
7  *
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.
11  *
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.
16  *
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.
20  *
21  */
22
23 #define EXPORT_SYMTAB
24
25 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/kernel.h>
28
29 #define DEBUG_SUBSYSTEM S_MDC
30
31 #include <linux/obd_class.h>
32 #include <linux/lustre_mds.h>
33
34 static int mdc_reint(struct ptlrpc_client *cl, struct ptlrpc_request *request)
35 {
36         int rc; 
37
38         rc = ptlrpc_queue_wait(cl, request);
39         if (rc)
40                 CERROR("error in handling %d\n", rc); 
41
42         return rc;
43 }
44
45 int mdc_setattr(struct ptlrpc_client *peer, 
46                 struct inode *inode, struct iattr *iattr,
47                 struct ptlrpc_request **request)
48 {
49         int rc; 
50         struct mds_rec_setattr *rec;
51         ENTRY;
52
53         *request = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL,
54                                    sizeof(*rec), NULL);
55         if (!(*request)) { 
56                 CERROR("cannot pack\n");
57                 EXIT;
58                 return -ENOMEM;
59         }
60
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);
66
67         rc = mdc_reint(peer, *request);
68
69         EXIT;
70         return rc;
71 }
72
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)
78 {
79         int rc; 
80         struct mds_rec_create *rec;
81         ENTRY;
82
83         (*request) = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL, 
84                                sizeof(*rec) + size_round0(namelen) + 
85                                size_round0(tgtlen), NULL);
86         if (!(*request)) { 
87                 CERROR("cannot pack\n");
88                 return -ENOMEM;
89         }
90
91         (*request)->rq_replen = 
92                 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
93
94         rec = mds_req_tgt((*request)->rq_req.mds);
95         mds_create_pack(rec, dir, name, namelen, mode, id, uid, gid, time, 
96                         tgt, tgtlen); 
97
98         rc = mdc_reint(peer, (*request));
99
100         EXIT;
101         return rc;
102 }
103
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)
107 {
108         int rc; 
109         struct mds_rec_unlink *rec;
110
111         (*request) = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL, 
112                                      sizeof(*rec) + size_round0(namelen), NULL);
113         if (!(*request)) { 
114                 CERROR("cannot pack\n");
115                 return -ENOMEM;
116         }
117
118         (*request)->rq_replen = 
119                 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
120
121         rec = mds_req_tgt((*request)->rq_req.mds);
122         mds_unlink_pack(rec, dir, child, name, namelen);
123
124         rc = mdc_reint(peer, (*request));
125
126         EXIT;
127         return rc;
128 }
129
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)
133 {
134         int rc; 
135         struct mds_rec_link *rec;
136         ENTRY;
137
138         (*request) = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL, 
139                                sizeof(*rec) + size_round0(namelen), NULL);
140         if (!(*request)) { 
141                 CERROR("cannot pack\n");
142                 return -ENOMEM;
143         }
144
145         (*request)->rq_replen = 
146                 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
147
148         rec = mds_req_tgt((*request)->rq_req.mds);
149         mds_link_pack(rec, src->d_inode, dir, name, namelen);
150
151         rc = mdc_reint(peer, (*request));
152         EXIT;
153         return rc;
154 }
155
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)
160 {
161         int rc; 
162         struct mds_rec_rename *rec;
163         ENTRY;
164
165         (*request) = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL, 
166                                sizeof(*rec) + size_round0(oldlen)
167                                + size_round0(newlen), NULL);
168         if (!(*request)) { 
169                 CERROR("cannot pack\n");
170                 return -ENOMEM;
171         }
172
173         (*request)->rq_replen = 
174                 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
175
176         rec = mds_req_tgt((*request)->rq_req.mds);
177         mds_rename_pack(rec, src, tgt, old, oldlen, new, newlen);
178
179         rc = mdc_reint(peer, (*request));
180
181         EXIT;
182         return rc;
183 }