Commit | Line | Data |
---|---|---|
53c06f4e AK |
1 | /* |
2 | * linux/fs/9p/vfs_inode_dotl.c | |
3 | * | |
4 | * This file contains vfs inode ops for the 9P2000.L protocol. | |
5 | * | |
6 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> | |
7 | * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License version 2 | |
11 | * as published by the Free Software Foundation. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to: | |
20 | * Free Software Foundation | |
21 | * 51 Franklin Street, Fifth Floor | |
22 | * Boston, MA 02111-1301 USA | |
23 | * | |
24 | */ | |
25 | ||
26 | #include <linux/module.h> | |
27 | #include <linux/errno.h> | |
28 | #include <linux/fs.h> | |
29 | #include <linux/file.h> | |
30 | #include <linux/pagemap.h> | |
31 | #include <linux/stat.h> | |
32 | #include <linux/string.h> | |
33 | #include <linux/inet.h> | |
34 | #include <linux/namei.h> | |
35 | #include <linux/idr.h> | |
36 | #include <linux/sched.h> | |
37 | #include <linux/slab.h> | |
38 | #include <linux/xattr.h> | |
39 | #include <linux/posix_acl.h> | |
40 | #include <net/9p/9p.h> | |
41 | #include <net/9p/client.h> | |
42 | ||
43 | #include "v9fs.h" | |
44 | #include "v9fs_vfs.h" | |
45 | #include "fid.h" | |
46 | #include "cache.h" | |
47 | #include "xattr.h" | |
48 | #include "acl.h" | |
49 | ||
50 | static int | |
51 | v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode, | |
52 | dev_t rdev); | |
53 | ||
54 | /** | |
55 | * v9fs_get_fsgid_for_create - Helper function to get the gid for creating a | |
56 | * new file system object. This checks the S_ISGID to determine the owning | |
57 | * group of the new file system object. | |
58 | */ | |
59 | ||
60 | static gid_t v9fs_get_fsgid_for_create(struct inode *dir_inode) | |
61 | { | |
62 | BUG_ON(dir_inode == NULL); | |
63 | ||
64 | if (dir_inode->i_mode & S_ISGID) { | |
65 | /* set_gid bit is set.*/ | |
66 | return dir_inode->i_gid; | |
67 | } | |
68 | return current_fsgid(); | |
69 | } | |
70 | ||
71 | /** | |
72 | * v9fs_dentry_from_dir_inode - helper function to get the dentry from | |
73 | * dir inode. | |
74 | * | |
75 | */ | |
76 | ||
77 | static struct dentry *v9fs_dentry_from_dir_inode(struct inode *inode) | |
78 | { | |
79 | struct dentry *dentry; | |
80 | ||
81 | spin_lock(&inode->i_lock); | |
82 | /* Directory should have only one entry. */ | |
83 | BUG_ON(S_ISDIR(inode->i_mode) && !list_is_singular(&inode->i_dentry)); | |
84 | dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias); | |
85 | spin_unlock(&inode->i_lock); | |
86 | return dentry; | |
87 | } | |
88 | ||
89 | struct inode * | |
90 | v9fs_inode_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid, | |
91 | struct super_block *sb) | |
92 | { | |
93 | struct inode *ret = NULL; | |
94 | int err; | |
95 | struct p9_stat_dotl *st; | |
96 | ||
97 | st = p9_client_getattr_dotl(fid, P9_STATS_BASIC); | |
98 | if (IS_ERR(st)) | |
99 | return ERR_CAST(st); | |
100 | ||
101 | ret = v9fs_get_inode(sb, st->st_mode); | |
102 | if (IS_ERR(ret)) { | |
103 | err = PTR_ERR(ret); | |
104 | goto error; | |
105 | } | |
106 | ||
107 | v9fs_stat2inode_dotl(st, ret); | |
108 | ret->i_ino = v9fs_qid2ino(&st->qid); | |
109 | #ifdef CONFIG_9P_FSCACHE | |
110 | v9fs_vcookie_set_qid(ret, &st->qid); | |
111 | v9fs_cache_inode_get_cookie(ret); | |
112 | #endif | |
113 | err = v9fs_get_acl(ret, fid); | |
114 | if (err) { | |
115 | iput(ret); | |
116 | goto error; | |
117 | } | |
118 | kfree(st); | |
119 | return ret; | |
120 | error: | |
121 | kfree(st); | |
122 | return ERR_PTR(err); | |
123 | } | |
124 | ||
125 | /** | |
126 | * v9fs_vfs_create_dotl - VFS hook to create files for 9P2000.L protocol. | |
127 | * @dir: directory inode that is being created | |
128 | * @dentry: dentry that is being deleted | |
129 | * @mode: create permissions | |
130 | * @nd: path information | |
131 | * | |
132 | */ | |
133 | ||
134 | static int | |
135 | v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode, | |
136 | struct nameidata *nd) | |
137 | { | |
138 | int err = 0; | |
139 | char *name = NULL; | |
140 | gid_t gid; | |
141 | int flags; | |
142 | mode_t mode; | |
143 | struct v9fs_session_info *v9ses; | |
144 | struct p9_fid *fid = NULL; | |
145 | struct p9_fid *dfid, *ofid; | |
146 | struct file *filp; | |
147 | struct p9_qid qid; | |
148 | struct inode *inode; | |
149 | struct posix_acl *pacl = NULL, *dacl = NULL; | |
150 | ||
151 | v9ses = v9fs_inode2v9ses(dir); | |
152 | if (nd && nd->flags & LOOKUP_OPEN) | |
153 | flags = nd->intent.open.flags - 1; | |
154 | else { | |
155 | /* | |
156 | * create call without LOOKUP_OPEN is due | |
157 | * to mknod of regular files. So use mknod | |
158 | * operation. | |
159 | */ | |
160 | return v9fs_vfs_mknod_dotl(dir, dentry, omode, 0); | |
161 | } | |
162 | ||
163 | name = (char *) dentry->d_name.name; | |
164 | P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_create_dotl: name:%s flags:0x%x " | |
165 | "mode:0x%x\n", name, flags, omode); | |
166 | ||
167 | dfid = v9fs_fid_lookup(dentry->d_parent); | |
168 | if (IS_ERR(dfid)) { | |
169 | err = PTR_ERR(dfid); | |
170 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); | |
171 | return err; | |
172 | } | |
173 | ||
174 | /* clone a fid to use for creation */ | |
175 | ofid = p9_client_walk(dfid, 0, NULL, 1); | |
176 | if (IS_ERR(ofid)) { | |
177 | err = PTR_ERR(ofid); | |
178 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); | |
179 | return err; | |
180 | } | |
181 | ||
182 | gid = v9fs_get_fsgid_for_create(dir); | |
183 | ||
184 | mode = omode; | |
185 | /* Update mode based on ACL value */ | |
186 | err = v9fs_acl_mode(dir, &mode, &dacl, &pacl); | |
187 | if (err) { | |
188 | P9_DPRINTK(P9_DEBUG_VFS, | |
189 | "Failed to get acl values in creat %d\n", err); | |
190 | goto error; | |
191 | } | |
192 | err = p9_client_create_dotl(ofid, name, flags, mode, gid, &qid); | |
193 | if (err < 0) { | |
194 | P9_DPRINTK(P9_DEBUG_VFS, | |
195 | "p9_client_open_dotl failed in creat %d\n", | |
196 | err); | |
197 | goto error; | |
198 | } | |
53c06f4e | 199 | |
af7542fc AK |
200 | /* instantiate inode and assign the unopened fid to the dentry */ |
201 | fid = p9_client_walk(dfid, 1, &name, 1); | |
202 | if (IS_ERR(fid)) { | |
203 | err = PTR_ERR(fid); | |
c25a61f5 | 204 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); |
53c06f4e | 205 | fid = NULL; |
af7542fc | 206 | goto error; |
53c06f4e | 207 | } |
af7542fc AK |
208 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); |
209 | if (IS_ERR(inode)) { | |
210 | err = PTR_ERR(inode); | |
211 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err); | |
212 | goto error; | |
213 | } | |
af7542fc AK |
214 | d_instantiate(dentry, inode); |
215 | err = v9fs_fid_add(dentry, fid); | |
216 | if (err < 0) | |
217 | goto error; | |
218 | ||
53c06f4e AK |
219 | /* Now set the ACL based on the default value */ |
220 | v9fs_set_create_acl(dentry, dacl, pacl); | |
221 | ||
af7542fc AK |
222 | /* Since we are opening a file, assign the open fid to the file */ |
223 | filp = lookup_instantiate_filp(nd, dentry, generic_file_open); | |
224 | if (IS_ERR(filp)) { | |
53c06f4e | 225 | p9_client_clunk(ofid); |
af7542fc AK |
226 | return PTR_ERR(filp); |
227 | } | |
228 | filp->private_data = ofid; | |
46848de0 AK |
229 | #ifdef CONFIG_9P_FSCACHE |
230 | if (v9ses->cache) | |
231 | v9fs_cache_inode_set_cookie(inode, filp); | |
232 | #endif | |
53c06f4e AK |
233 | return 0; |
234 | ||
235 | error: | |
236 | if (ofid) | |
237 | p9_client_clunk(ofid); | |
238 | if (fid) | |
239 | p9_client_clunk(fid); | |
240 | return err; | |
241 | } | |
242 | ||
243 | /** | |
244 | * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory | |
245 | * @dir: inode that is being unlinked | |
246 | * @dentry: dentry that is being unlinked | |
247 | * @mode: mode for new directory | |
248 | * | |
249 | */ | |
250 | ||
251 | static int v9fs_vfs_mkdir_dotl(struct inode *dir, | |
252 | struct dentry *dentry, int omode) | |
253 | { | |
254 | int err; | |
255 | struct v9fs_session_info *v9ses; | |
256 | struct p9_fid *fid = NULL, *dfid = NULL; | |
257 | gid_t gid; | |
258 | char *name; | |
259 | mode_t mode; | |
260 | struct inode *inode; | |
261 | struct p9_qid qid; | |
262 | struct dentry *dir_dentry; | |
263 | struct posix_acl *dacl = NULL, *pacl = NULL; | |
264 | ||
265 | P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name); | |
266 | err = 0; | |
267 | v9ses = v9fs_inode2v9ses(dir); | |
268 | ||
269 | omode |= S_IFDIR; | |
270 | if (dir->i_mode & S_ISGID) | |
271 | omode |= S_ISGID; | |
272 | ||
273 | dir_dentry = v9fs_dentry_from_dir_inode(dir); | |
274 | dfid = v9fs_fid_lookup(dir_dentry); | |
275 | if (IS_ERR(dfid)) { | |
276 | err = PTR_ERR(dfid); | |
277 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); | |
278 | dfid = NULL; | |
279 | goto error; | |
280 | } | |
281 | ||
282 | gid = v9fs_get_fsgid_for_create(dir); | |
283 | mode = omode; | |
284 | /* Update mode based on ACL value */ | |
285 | err = v9fs_acl_mode(dir, &mode, &dacl, &pacl); | |
286 | if (err) { | |
287 | P9_DPRINTK(P9_DEBUG_VFS, | |
288 | "Failed to get acl values in mkdir %d\n", err); | |
289 | goto error; | |
290 | } | |
291 | name = (char *) dentry->d_name.name; | |
292 | err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid); | |
293 | if (err < 0) | |
294 | goto error; | |
295 | ||
296 | /* instantiate inode and assign the unopened fid to the dentry */ | |
297 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) { | |
298 | fid = p9_client_walk(dfid, 1, &name, 1); | |
299 | if (IS_ERR(fid)) { | |
300 | err = PTR_ERR(fid); | |
301 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", | |
302 | err); | |
303 | fid = NULL; | |
304 | goto error; | |
305 | } | |
306 | ||
307 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); | |
308 | if (IS_ERR(inode)) { | |
309 | err = PTR_ERR(inode); | |
310 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", | |
311 | err); | |
312 | goto error; | |
313 | } | |
53c06f4e AK |
314 | d_instantiate(dentry, inode); |
315 | err = v9fs_fid_add(dentry, fid); | |
316 | if (err < 0) | |
317 | goto error; | |
318 | fid = NULL; | |
319 | } else { | |
320 | /* | |
321 | * Not in cached mode. No need to populate | |
322 | * inode with stat. We need to get an inode | |
323 | * so that we can set the acl with dentry | |
324 | */ | |
325 | inode = v9fs_get_inode(dir->i_sb, mode); | |
326 | if (IS_ERR(inode)) { | |
327 | err = PTR_ERR(inode); | |
328 | goto error; | |
329 | } | |
53c06f4e AK |
330 | d_instantiate(dentry, inode); |
331 | } | |
332 | /* Now set the ACL based on the default value */ | |
333 | v9fs_set_create_acl(dentry, dacl, pacl); | |
334 | ||
335 | error: | |
336 | if (fid) | |
337 | p9_client_clunk(fid); | |
338 | return err; | |
339 | } | |
340 | ||
341 | static int | |
342 | v9fs_vfs_getattr_dotl(struct vfsmount *mnt, struct dentry *dentry, | |
343 | struct kstat *stat) | |
344 | { | |
345 | int err; | |
346 | struct v9fs_session_info *v9ses; | |
347 | struct p9_fid *fid; | |
348 | struct p9_stat_dotl *st; | |
349 | ||
350 | P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry); | |
351 | err = -EPERM; | |
352 | v9ses = v9fs_inode2v9ses(dentry->d_inode); | |
353 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) | |
354 | return simple_getattr(mnt, dentry, stat); | |
355 | ||
356 | fid = v9fs_fid_lookup(dentry); | |
357 | if (IS_ERR(fid)) | |
358 | return PTR_ERR(fid); | |
359 | ||
360 | /* Ask for all the fields in stat structure. Server will return | |
361 | * whatever it supports | |
362 | */ | |
363 | ||
364 | st = p9_client_getattr_dotl(fid, P9_STATS_ALL); | |
365 | if (IS_ERR(st)) | |
366 | return PTR_ERR(st); | |
367 | ||
368 | v9fs_stat2inode_dotl(st, dentry->d_inode); | |
369 | generic_fillattr(dentry->d_inode, stat); | |
370 | /* Change block size to what the server returned */ | |
371 | stat->blksize = st->st_blksize; | |
372 | ||
373 | kfree(st); | |
374 | return 0; | |
375 | } | |
376 | ||
377 | /** | |
378 | * v9fs_vfs_setattr_dotl - set file metadata | |
379 | * @dentry: file whose metadata to set | |
380 | * @iattr: metadata assignment structure | |
381 | * | |
382 | */ | |
383 | ||
384 | int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr) | |
385 | { | |
386 | int retval; | |
387 | struct v9fs_session_info *v9ses; | |
388 | struct p9_fid *fid; | |
389 | struct p9_iattr_dotl p9attr; | |
390 | ||
391 | P9_DPRINTK(P9_DEBUG_VFS, "\n"); | |
392 | ||
393 | retval = inode_change_ok(dentry->d_inode, iattr); | |
394 | if (retval) | |
395 | return retval; | |
396 | ||
397 | p9attr.valid = iattr->ia_valid; | |
398 | p9attr.mode = iattr->ia_mode; | |
399 | p9attr.uid = iattr->ia_uid; | |
400 | p9attr.gid = iattr->ia_gid; | |
401 | p9attr.size = iattr->ia_size; | |
402 | p9attr.atime_sec = iattr->ia_atime.tv_sec; | |
403 | p9attr.atime_nsec = iattr->ia_atime.tv_nsec; | |
404 | p9attr.mtime_sec = iattr->ia_mtime.tv_sec; | |
405 | p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec; | |
406 | ||
407 | retval = -EPERM; | |
408 | v9ses = v9fs_inode2v9ses(dentry->d_inode); | |
409 | fid = v9fs_fid_lookup(dentry); | |
410 | if (IS_ERR(fid)) | |
411 | return PTR_ERR(fid); | |
412 | ||
413 | retval = p9_client_setattr(fid, &p9attr); | |
414 | if (retval < 0) | |
415 | return retval; | |
416 | ||
417 | if ((iattr->ia_valid & ATTR_SIZE) && | |
418 | iattr->ia_size != i_size_read(dentry->d_inode)) { | |
419 | retval = vmtruncate(dentry->d_inode, iattr->ia_size); | |
420 | if (retval) | |
421 | return retval; | |
422 | } | |
423 | ||
424 | setattr_copy(dentry->d_inode, iattr); | |
425 | mark_inode_dirty(dentry->d_inode); | |
426 | if (iattr->ia_valid & ATTR_MODE) { | |
427 | /* We also want to update ACL when we update mode bits */ | |
428 | retval = v9fs_acl_chmod(dentry); | |
429 | if (retval < 0) | |
430 | return retval; | |
431 | } | |
432 | return 0; | |
433 | } | |
434 | ||
435 | /** | |
436 | * v9fs_stat2inode_dotl - populate an inode structure with stat info | |
437 | * @stat: stat structure | |
438 | * @inode: inode to populate | |
439 | * @sb: superblock of filesystem | |
440 | * | |
441 | */ | |
442 | ||
443 | void | |
444 | v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode) | |
445 | { | |
446 | ||
447 | if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) { | |
448 | inode->i_atime.tv_sec = stat->st_atime_sec; | |
449 | inode->i_atime.tv_nsec = stat->st_atime_nsec; | |
450 | inode->i_mtime.tv_sec = stat->st_mtime_sec; | |
451 | inode->i_mtime.tv_nsec = stat->st_mtime_nsec; | |
452 | inode->i_ctime.tv_sec = stat->st_ctime_sec; | |
453 | inode->i_ctime.tv_nsec = stat->st_ctime_nsec; | |
454 | inode->i_uid = stat->st_uid; | |
455 | inode->i_gid = stat->st_gid; | |
456 | inode->i_nlink = stat->st_nlink; | |
457 | inode->i_mode = stat->st_mode; | |
458 | inode->i_rdev = new_decode_dev(stat->st_rdev); | |
459 | ||
460 | if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) | |
461 | init_special_inode(inode, inode->i_mode, inode->i_rdev); | |
462 | ||
463 | i_size_write(inode, stat->st_size); | |
464 | inode->i_blocks = stat->st_blocks; | |
465 | } else { | |
466 | if (stat->st_result_mask & P9_STATS_ATIME) { | |
467 | inode->i_atime.tv_sec = stat->st_atime_sec; | |
468 | inode->i_atime.tv_nsec = stat->st_atime_nsec; | |
469 | } | |
470 | if (stat->st_result_mask & P9_STATS_MTIME) { | |
471 | inode->i_mtime.tv_sec = stat->st_mtime_sec; | |
472 | inode->i_mtime.tv_nsec = stat->st_mtime_nsec; | |
473 | } | |
474 | if (stat->st_result_mask & P9_STATS_CTIME) { | |
475 | inode->i_ctime.tv_sec = stat->st_ctime_sec; | |
476 | inode->i_ctime.tv_nsec = stat->st_ctime_nsec; | |
477 | } | |
478 | if (stat->st_result_mask & P9_STATS_UID) | |
479 | inode->i_uid = stat->st_uid; | |
480 | if (stat->st_result_mask & P9_STATS_GID) | |
481 | inode->i_gid = stat->st_gid; | |
482 | if (stat->st_result_mask & P9_STATS_NLINK) | |
483 | inode->i_nlink = stat->st_nlink; | |
484 | if (stat->st_result_mask & P9_STATS_MODE) { | |
485 | inode->i_mode = stat->st_mode; | |
486 | if ((S_ISBLK(inode->i_mode)) || | |
487 | (S_ISCHR(inode->i_mode))) | |
488 | init_special_inode(inode, inode->i_mode, | |
489 | inode->i_rdev); | |
490 | } | |
491 | if (stat->st_result_mask & P9_STATS_RDEV) | |
492 | inode->i_rdev = new_decode_dev(stat->st_rdev); | |
493 | if (stat->st_result_mask & P9_STATS_SIZE) | |
494 | i_size_write(inode, stat->st_size); | |
495 | if (stat->st_result_mask & P9_STATS_BLOCKS) | |
496 | inode->i_blocks = stat->st_blocks; | |
497 | } | |
498 | if (stat->st_result_mask & P9_STATS_GEN) | |
499 | inode->i_generation = stat->st_gen; | |
500 | ||
501 | /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION | |
502 | * because the inode structure does not have fields for them. | |
503 | */ | |
504 | } | |
505 | ||
506 | static int | |
507 | v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry, | |
508 | const char *symname) | |
509 | { | |
510 | struct v9fs_session_info *v9ses; | |
511 | struct p9_fid *dfid; | |
512 | struct p9_fid *fid = NULL; | |
513 | struct inode *inode; | |
514 | struct p9_qid qid; | |
515 | char *name; | |
516 | int err; | |
517 | gid_t gid; | |
518 | ||
519 | name = (char *) dentry->d_name.name; | |
520 | P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_symlink_dotl : %lu,%s,%s\n", | |
521 | dir->i_ino, name, symname); | |
522 | v9ses = v9fs_inode2v9ses(dir); | |
523 | ||
524 | dfid = v9fs_fid_lookup(dentry->d_parent); | |
525 | if (IS_ERR(dfid)) { | |
526 | err = PTR_ERR(dfid); | |
527 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); | |
528 | return err; | |
529 | } | |
530 | ||
531 | gid = v9fs_get_fsgid_for_create(dir); | |
532 | ||
533 | /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */ | |
534 | err = p9_client_symlink(dfid, name, (char *)symname, gid, &qid); | |
535 | ||
536 | if (err < 0) { | |
537 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err); | |
538 | goto error; | |
539 | } | |
540 | ||
541 | if (v9ses->cache) { | |
542 | /* Now walk from the parent so we can get an unopened fid. */ | |
543 | fid = p9_client_walk(dfid, 1, &name, 1); | |
544 | if (IS_ERR(fid)) { | |
545 | err = PTR_ERR(fid); | |
546 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", | |
547 | err); | |
548 | fid = NULL; | |
549 | goto error; | |
550 | } | |
551 | ||
552 | /* instantiate inode and assign the unopened fid to dentry */ | |
553 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); | |
554 | if (IS_ERR(inode)) { | |
555 | err = PTR_ERR(inode); | |
556 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", | |
557 | err); | |
558 | goto error; | |
559 | } | |
53c06f4e AK |
560 | d_instantiate(dentry, inode); |
561 | err = v9fs_fid_add(dentry, fid); | |
562 | if (err < 0) | |
563 | goto error; | |
564 | fid = NULL; | |
565 | } else { | |
566 | /* Not in cached mode. No need to populate inode with stat */ | |
567 | inode = v9fs_get_inode(dir->i_sb, S_IFLNK); | |
568 | if (IS_ERR(inode)) { | |
569 | err = PTR_ERR(inode); | |
570 | goto error; | |
571 | } | |
53c06f4e AK |
572 | d_instantiate(dentry, inode); |
573 | } | |
574 | ||
575 | error: | |
576 | if (fid) | |
577 | p9_client_clunk(fid); | |
578 | ||
579 | return err; | |
580 | } | |
581 | ||
582 | /** | |
583 | * v9fs_vfs_link_dotl - create a hardlink for dotl | |
584 | * @old_dentry: dentry for file to link to | |
585 | * @dir: inode destination for new link | |
586 | * @dentry: dentry for link | |
587 | * | |
588 | */ | |
589 | ||
590 | static int | |
591 | v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir, | |
592 | struct dentry *dentry) | |
593 | { | |
594 | int err; | |
595 | struct p9_fid *dfid, *oldfid; | |
596 | char *name; | |
597 | struct v9fs_session_info *v9ses; | |
598 | struct dentry *dir_dentry; | |
599 | ||
600 | P9_DPRINTK(P9_DEBUG_VFS, "dir ino: %lu, old_name: %s, new_name: %s\n", | |
601 | dir->i_ino, old_dentry->d_name.name, | |
602 | dentry->d_name.name); | |
603 | ||
604 | v9ses = v9fs_inode2v9ses(dir); | |
605 | dir_dentry = v9fs_dentry_from_dir_inode(dir); | |
606 | dfid = v9fs_fid_lookup(dir_dentry); | |
607 | if (IS_ERR(dfid)) | |
608 | return PTR_ERR(dfid); | |
609 | ||
610 | oldfid = v9fs_fid_lookup(old_dentry); | |
611 | if (IS_ERR(oldfid)) | |
612 | return PTR_ERR(oldfid); | |
613 | ||
614 | name = (char *) dentry->d_name.name; | |
615 | ||
616 | err = p9_client_link(dfid, oldfid, (char *)dentry->d_name.name); | |
617 | ||
618 | if (err < 0) { | |
619 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_link failed %d\n", err); | |
620 | return err; | |
621 | } | |
622 | ||
623 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) { | |
624 | /* Get the latest stat info from server. */ | |
625 | struct p9_fid *fid; | |
626 | struct p9_stat_dotl *st; | |
627 | ||
628 | fid = v9fs_fid_lookup(old_dentry); | |
629 | if (IS_ERR(fid)) | |
630 | return PTR_ERR(fid); | |
631 | ||
632 | st = p9_client_getattr_dotl(fid, P9_STATS_BASIC); | |
633 | if (IS_ERR(st)) | |
634 | return PTR_ERR(st); | |
635 | ||
636 | v9fs_stat2inode_dotl(st, old_dentry->d_inode); | |
637 | ||
638 | kfree(st); | |
639 | } else { | |
640 | /* Caching disabled. No need to get upto date stat info. | |
641 | * This dentry will be released immediately. So, just hold the | |
642 | * inode | |
643 | */ | |
644 | ihold(old_dentry->d_inode); | |
645 | } | |
53c06f4e AK |
646 | d_instantiate(dentry, old_dentry->d_inode); |
647 | ||
648 | return err; | |
649 | } | |
650 | ||
651 | /** | |
652 | * v9fs_vfs_mknod_dotl - create a special file | |
653 | * @dir: inode destination for new link | |
654 | * @dentry: dentry for file | |
655 | * @mode: mode for creation | |
656 | * @rdev: device associated with special file | |
657 | * | |
658 | */ | |
659 | static int | |
660 | v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode, | |
661 | dev_t rdev) | |
662 | { | |
663 | int err; | |
664 | char *name; | |
665 | mode_t mode; | |
666 | struct v9fs_session_info *v9ses; | |
667 | struct p9_fid *fid = NULL, *dfid = NULL; | |
668 | struct inode *inode; | |
669 | gid_t gid; | |
670 | struct p9_qid qid; | |
671 | struct dentry *dir_dentry; | |
672 | struct posix_acl *dacl = NULL, *pacl = NULL; | |
673 | ||
674 | P9_DPRINTK(P9_DEBUG_VFS, | |
675 | " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino, | |
676 | dentry->d_name.name, omode, MAJOR(rdev), MINOR(rdev)); | |
677 | ||
678 | if (!new_valid_dev(rdev)) | |
679 | return -EINVAL; | |
680 | ||
681 | v9ses = v9fs_inode2v9ses(dir); | |
682 | dir_dentry = v9fs_dentry_from_dir_inode(dir); | |
683 | dfid = v9fs_fid_lookup(dir_dentry); | |
684 | if (IS_ERR(dfid)) { | |
685 | err = PTR_ERR(dfid); | |
686 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); | |
687 | dfid = NULL; | |
688 | goto error; | |
689 | } | |
690 | ||
691 | gid = v9fs_get_fsgid_for_create(dir); | |
692 | mode = omode; | |
693 | /* Update mode based on ACL value */ | |
694 | err = v9fs_acl_mode(dir, &mode, &dacl, &pacl); | |
695 | if (err) { | |
696 | P9_DPRINTK(P9_DEBUG_VFS, | |
697 | "Failed to get acl values in mknod %d\n", err); | |
698 | goto error; | |
699 | } | |
700 | name = (char *) dentry->d_name.name; | |
701 | ||
702 | err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid); | |
703 | if (err < 0) | |
704 | goto error; | |
705 | ||
706 | /* instantiate inode and assign the unopened fid to the dentry */ | |
707 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) { | |
708 | fid = p9_client_walk(dfid, 1, &name, 1); | |
709 | if (IS_ERR(fid)) { | |
710 | err = PTR_ERR(fid); | |
711 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", | |
712 | err); | |
713 | fid = NULL; | |
714 | goto error; | |
715 | } | |
716 | ||
717 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); | |
718 | if (IS_ERR(inode)) { | |
719 | err = PTR_ERR(inode); | |
720 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", | |
721 | err); | |
722 | goto error; | |
723 | } | |
53c06f4e AK |
724 | d_instantiate(dentry, inode); |
725 | err = v9fs_fid_add(dentry, fid); | |
726 | if (err < 0) | |
727 | goto error; | |
728 | fid = NULL; | |
729 | } else { | |
730 | /* | |
731 | * Not in cached mode. No need to populate inode with stat. | |
732 | * socket syscall returns a fd, so we need instantiate | |
733 | */ | |
734 | inode = v9fs_get_inode(dir->i_sb, mode); | |
735 | if (IS_ERR(inode)) { | |
736 | err = PTR_ERR(inode); | |
737 | goto error; | |
738 | } | |
53c06f4e AK |
739 | d_instantiate(dentry, inode); |
740 | } | |
741 | /* Now set the ACL based on the default value */ | |
742 | v9fs_set_create_acl(dentry, dacl, pacl); | |
743 | error: | |
744 | if (fid) | |
745 | p9_client_clunk(fid); | |
746 | return err; | |
747 | } | |
748 | ||
53c06f4e AK |
749 | /** |
750 | * v9fs_vfs_follow_link_dotl - follow a symlink path | |
751 | * @dentry: dentry for symlink | |
752 | * @nd: nameidata | |
753 | * | |
754 | */ | |
755 | ||
756 | static void * | |
757 | v9fs_vfs_follow_link_dotl(struct dentry *dentry, struct nameidata *nd) | |
758 | { | |
31b6ceac MK |
759 | int retval; |
760 | struct p9_fid *fid; | |
53c06f4e | 761 | char *link = __getname(); |
31b6ceac | 762 | char *target; |
53c06f4e | 763 | |
31b6ceac | 764 | P9_DPRINTK(P9_DEBUG_VFS, "%s\n", dentry->d_name.name); |
53c06f4e | 765 | |
31b6ceac | 766 | if (!link) { |
53c06f4e | 767 | link = ERR_PTR(-ENOMEM); |
31b6ceac | 768 | goto ndset; |
53c06f4e | 769 | } |
31b6ceac MK |
770 | fid = v9fs_fid_lookup(dentry); |
771 | if (IS_ERR(fid)) { | |
772 | __putname(link); | |
773 | link = ERR_PTR(PTR_ERR(fid)); | |
774 | goto ndset; | |
775 | } | |
776 | retval = p9_client_readlink(fid, &target); | |
777 | if (!retval) { | |
778 | strcpy(link, target); | |
779 | kfree(target); | |
780 | goto ndset; | |
781 | } | |
782 | __putname(link); | |
783 | link = ERR_PTR(retval); | |
784 | ndset: | |
53c06f4e | 785 | nd_set_link(nd, link); |
53c06f4e AK |
786 | return NULL; |
787 | } | |
788 | ||
789 | const struct inode_operations v9fs_dir_inode_operations_dotl = { | |
790 | .create = v9fs_vfs_create_dotl, | |
791 | .lookup = v9fs_vfs_lookup, | |
792 | .link = v9fs_vfs_link_dotl, | |
793 | .symlink = v9fs_vfs_symlink_dotl, | |
794 | .unlink = v9fs_vfs_unlink, | |
795 | .mkdir = v9fs_vfs_mkdir_dotl, | |
796 | .rmdir = v9fs_vfs_rmdir, | |
797 | .mknod = v9fs_vfs_mknod_dotl, | |
798 | .rename = v9fs_vfs_rename, | |
799 | .getattr = v9fs_vfs_getattr_dotl, | |
800 | .setattr = v9fs_vfs_setattr_dotl, | |
801 | .setxattr = generic_setxattr, | |
802 | .getxattr = generic_getxattr, | |
803 | .removexattr = generic_removexattr, | |
804 | .listxattr = v9fs_listxattr, | |
805 | .check_acl = v9fs_check_acl, | |
806 | }; | |
807 | ||
808 | const struct inode_operations v9fs_file_inode_operations_dotl = { | |
809 | .getattr = v9fs_vfs_getattr_dotl, | |
810 | .setattr = v9fs_vfs_setattr_dotl, | |
811 | .setxattr = generic_setxattr, | |
812 | .getxattr = generic_getxattr, | |
813 | .removexattr = generic_removexattr, | |
814 | .listxattr = v9fs_listxattr, | |
815 | .check_acl = v9fs_check_acl, | |
816 | }; | |
817 | ||
818 | const struct inode_operations v9fs_symlink_inode_operations_dotl = { | |
31b6ceac | 819 | .readlink = generic_readlink, |
53c06f4e AK |
820 | .follow_link = v9fs_vfs_follow_link_dotl, |
821 | .put_link = v9fs_vfs_put_link, | |
822 | .getattr = v9fs_vfs_getattr_dotl, | |
823 | .setattr = v9fs_vfs_setattr_dotl, | |
824 | .setxattr = generic_setxattr, | |
825 | .getxattr = generic_getxattr, | |
826 | .removexattr = generic_removexattr, | |
827 | .listxattr = v9fs_listxattr, | |
828 | }; |