Whamcloud - gitweb
This adds most of the metadata infrastructure: I think that all commands
[fs/lustre-release.git] / lustre / mdc / mdc_reint.c
1 /*
2  * Copryright (C) 2001 Cluster File Systems, Inc.
3  *
4  */
5
6 #define EXPORT_SYMTAB
7
8 #include <linux/config.h>
9 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/mm.h>
12 #include <linux/string.h>
13 #include <linux/stat.h>
14 #include <linux/errno.h>
15 #include <linux/locks.h>
16 #include <linux/unistd.h>
17
18 #include <asm/system.h>
19 #include <asm/uaccess.h>
20 #include <linux/module.h>
21
22 #include <linux/fs.h>
23 #include <linux/stat.h>
24 #include <asm/uaccess.h>
25 #include <linux/vmalloc.h>
26 #include <asm/segment.h>
27 #include <linux/miscdevice.h>
28
29 #include <linux/obd_support.h>
30 #include <linux/lustre_lib.h>
31 #include <linux/lustre_idl.h>
32 #include <linux/lustre_mds.h>
33
34 extern int mdc_reint(struct lustre_peer *peer, struct ptlrpc_request *request);
35 extern struct ptlrpc_request *mds_prep_req(int opcode, int namelen, char *name, int tgtlen, char *tgt);
36
37 int mdc_setattr(struct lustre_peer *peer, 
38                 struct inode *inode, struct iattr *iattr,
39                 struct mds_rep **rep, struct ptlrep_hdr **hdr)
40 {
41         int rc; 
42         struct ptlrpc_request *request;
43         struct mds_rec_setattr *rec;
44
45         request = mds_prep_req(MDS_REINT, 0, NULL, sizeof(*rec), NULL);
46         if (!request) { 
47                 printk("mdc request: cannot pack\n");
48                 return -ENOMEM;
49         }
50
51         rec = mds_req_tgt(request->rq_req.mds);
52         mds_setattr_pack(rec, inode, iattr); 
53         request->rq_req.mds->opcode = HTON__u32(REINT_SETATTR);
54         request->rq_replen = 
55                 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
56
57         rc = mdc_reint(peer, request);
58         if (rc)
59                 return rc;
60
61         if (rep) { 
62                 *rep = request->rq_rep.mds;
63         }
64         if (hdr) { 
65                 *hdr = request->rq_rephdr;
66         }
67
68         return 0;
69 }
70
71 int mdc_create(struct lustre_peer *peer, 
72                struct inode *dir, const char *name, int namelen, 
73                const char *tgt, int tgtlen, 
74                int mode, __u64 id, __u32 uid, __u32 gid, __u64 time, 
75                 struct mds_rep **rep, struct ptlrep_hdr **hdr)
76 {
77         int rc; 
78         struct ptlrpc_request *request;
79         struct mds_rec_create *rec;
80
81         request = mds_prep_req(MDS_REINT, 0, NULL, 
82                                sizeof(*rec) + size_round0(namelen) + 
83                                size_round0(tgtlen), NULL);
84         if (!request) { 
85                 printk("mdc_create: cannot pack\n");
86                 return -ENOMEM;
87         }
88
89         request->rq_replen = 
90                 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
91
92         rec = mds_req_tgt(request->rq_req.mds);
93         mds_create_pack(rec, dir, name, namelen, mode, id, uid, gid, time, 
94                         tgt, tgtlen); 
95
96         rc = mdc_reint(peer, request);
97
98         if (rep) { 
99                 *rep = request->rq_rep.mds;
100         }
101         if (hdr) { 
102                 *hdr = request->rq_rephdr;
103         }
104
105         kfree(request); 
106         return rc;
107 }
108
109 int mdc_unlink(struct lustre_peer *peer, 
110                struct inode *dir, const char *name, int namelen, 
111                 struct mds_rep **rep, struct ptlrep_hdr **hdr)
112 {
113         int rc; 
114         struct ptlrpc_request *request;
115         struct mds_rec_unlink *rec;
116
117         request = mds_prep_req(MDS_REINT, 0, NULL, 
118                                sizeof(*rec) + size_round0(namelen), NULL);
119         if (!request) { 
120                 printk("mdc_unlink: cannot pack\n");
121                 return -ENOMEM;
122         }
123
124         request->rq_replen = 
125                 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
126
127         rec = mds_req_tgt(request->rq_req.mds);
128         mds_unlink_pack(rec, dir, name, namelen);
129
130         rc = mdc_reint(peer, request);
131
132         if (rep) { 
133                 *rep = request->rq_rep.mds;
134         }
135         if (hdr) { 
136                 *hdr = request->rq_rephdr;
137         }
138
139         kfree(request); 
140         return rc;
141 }
142
143 int mdc_link(struct lustre_peer *peer, struct dentry *src, 
144              struct inode *dir, const char *name, int namelen, 
145                 struct mds_rep **rep, struct ptlrep_hdr **hdr)
146 {
147         int rc; 
148         struct ptlrpc_request *request;
149         struct mds_rec_link *rec;
150
151         request = mds_prep_req(MDS_REINT, 0, NULL, 
152                                sizeof(*rec) + size_round0(namelen), NULL);
153         if (!request) { 
154                 printk("mdc_link: cannot pack\n");
155                 return -ENOMEM;
156         }
157
158         request->rq_replen = 
159                 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
160
161         rec = mds_req_tgt(request->rq_req.mds);
162         mds_link_pack(rec, src->d_inode, dir, name, namelen);
163
164         rc = mdc_reint(peer, request);
165
166         if (rep) { 
167                 *rep = request->rq_rep.mds;
168         }
169         if (hdr) { 
170                 *hdr = request->rq_rephdr;
171         }
172
173         kfree(request); 
174         return rc;
175 }
176
177 int mdc_rename(struct lustre_peer *peer, struct inode *src, 
178                struct inode *tgt, const char *old, int oldlen, 
179                const char *new, int newlen, 
180                struct mds_rep **rep, struct ptlrep_hdr **hdr)
181 {
182         int rc; 
183         struct ptlrpc_request *request;
184         struct mds_rec_rename *rec;
185
186         request = mds_prep_req(MDS_REINT, 0, NULL, 
187                                sizeof(*rec) + size_round0(oldlen)
188                                + size_round0(newlen), NULL);
189         if (!request) { 
190                 printk("mdc_link: cannot pack\n");
191                 return -ENOMEM;
192         }
193
194         request->rq_replen = 
195                 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
196
197         rec = mds_req_tgt(request->rq_req.mds);
198         mds_rename_pack(rec, src, tgt, old, oldlen, new, newlen);
199
200         rc = mdc_reint(peer, request);
201
202         if (rep) { 
203                 *rep = request->rq_rep.mds;
204         }
205         if (hdr) { 
206                 *hdr = request->rq_rephdr;
207         }
208
209         kfree(request); 
210         return rc;
211 }