blob: b6f3977545f78d39519ec558f8a56cfb194356a4 [file] [log] [blame]
Aneesh Kumar K.V53c06f42011-01-10 13:51:47 -06001/*
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
50static int
51v9fs_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
60static 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
77static 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
89struct inode *
90v9fs_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;
120error:
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
134static int
135v9fs_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 }
Aneesh Kumar K.V53c06f42011-01-10 13:51:47 -0600199
Aneesh Kumar K.Vaf7542f2011-01-10 14:22:21 -0600200 /* 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);
204 P9_DPRINTK(P9_DEBUG_VFS, "p9_clinet_walk failed %d\n", err);
Aneesh Kumar K.V53c06f42011-01-10 13:51:47 -0600205 fid = NULL;
Aneesh Kumar K.Vaf7542f2011-01-10 14:22:21 -0600206 goto error;
Aneesh Kumar K.V53c06f42011-01-10 13:51:47 -0600207 }
Aneesh Kumar K.Vaf7542f2011-01-10 14:22:21 -0600208 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 }
214 if (v9ses->cache)
215 dentry->d_op = &v9fs_cached_dentry_operations;
216 else
217 dentry->d_op = &v9fs_dentry_operations;
218
219 d_instantiate(dentry, inode);
220 err = v9fs_fid_add(dentry, fid);
221 if (err < 0)
222 goto error;
223
Aneesh Kumar K.V53c06f42011-01-10 13:51:47 -0600224 /* Now set the ACL based on the default value */
225 v9fs_set_create_acl(dentry, dacl, pacl);
226
Aneesh Kumar K.Vaf7542f2011-01-10 14:22:21 -0600227 /* Since we are opening a file, assign the open fid to the file */
228 filp = lookup_instantiate_filp(nd, dentry, generic_file_open);
229 if (IS_ERR(filp)) {
Aneesh Kumar K.V53c06f42011-01-10 13:51:47 -0600230 p9_client_clunk(ofid);
Aneesh Kumar K.Vaf7542f2011-01-10 14:22:21 -0600231 return PTR_ERR(filp);
232 }
233 filp->private_data = ofid;
Aneesh Kumar K.V53c06f42011-01-10 13:51:47 -0600234 return 0;
235
236error:
237 if (ofid)
238 p9_client_clunk(ofid);
239 if (fid)
240 p9_client_clunk(fid);
241 return err;
242}
243
244/**
245 * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory
246 * @dir: inode that is being unlinked
247 * @dentry: dentry that is being unlinked
248 * @mode: mode for new directory
249 *
250 */
251
252static int v9fs_vfs_mkdir_dotl(struct inode *dir,
253 struct dentry *dentry, int omode)
254{
255 int err;
256 struct v9fs_session_info *v9ses;
257 struct p9_fid *fid = NULL, *dfid = NULL;
258 gid_t gid;
259 char *name;
260 mode_t mode;
261 struct inode *inode;
262 struct p9_qid qid;
263 struct dentry *dir_dentry;
264 struct posix_acl *dacl = NULL, *pacl = NULL;
265
266 P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
267 err = 0;
268 v9ses = v9fs_inode2v9ses(dir);
269
270 omode |= S_IFDIR;
271 if (dir->i_mode & S_ISGID)
272 omode |= S_ISGID;
273
274 dir_dentry = v9fs_dentry_from_dir_inode(dir);
275 dfid = v9fs_fid_lookup(dir_dentry);
276 if (IS_ERR(dfid)) {
277 err = PTR_ERR(dfid);
278 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
279 dfid = NULL;
280 goto error;
281 }
282
283 gid = v9fs_get_fsgid_for_create(dir);
284 mode = omode;
285 /* Update mode based on ACL value */
286 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
287 if (err) {
288 P9_DPRINTK(P9_DEBUG_VFS,
289 "Failed to get acl values in mkdir %d\n", err);
290 goto error;
291 }
292 name = (char *) dentry->d_name.name;
293 err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid);
294 if (err < 0)
295 goto error;
296
297 /* instantiate inode and assign the unopened fid to the dentry */
298 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
299 fid = p9_client_walk(dfid, 1, &name, 1);
300 if (IS_ERR(fid)) {
301 err = PTR_ERR(fid);
302 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
303 err);
304 fid = NULL;
305 goto error;
306 }
307
308 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
309 if (IS_ERR(inode)) {
310 err = PTR_ERR(inode);
311 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
312 err);
313 goto error;
314 }
315 d_set_d_op(dentry, &v9fs_cached_dentry_operations);
316 d_instantiate(dentry, inode);
317 err = v9fs_fid_add(dentry, fid);
318 if (err < 0)
319 goto error;
320 fid = NULL;
321 } else {
322 /*
323 * Not in cached mode. No need to populate
324 * inode with stat. We need to get an inode
325 * so that we can set the acl with dentry
326 */
327 inode = v9fs_get_inode(dir->i_sb, mode);
328 if (IS_ERR(inode)) {
329 err = PTR_ERR(inode);
330 goto error;
331 }
332 d_set_d_op(dentry, &v9fs_dentry_operations);
333 d_instantiate(dentry, inode);
334 }
335 /* Now set the ACL based on the default value */
336 v9fs_set_create_acl(dentry, dacl, pacl);
337
338error:
339 if (fid)
340 p9_client_clunk(fid);
341 return err;
342}
343
344static int
345v9fs_vfs_getattr_dotl(struct vfsmount *mnt, struct dentry *dentry,
346 struct kstat *stat)
347{
348 int err;
349 struct v9fs_session_info *v9ses;
350 struct p9_fid *fid;
351 struct p9_stat_dotl *st;
352
353 P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
354 err = -EPERM;
355 v9ses = v9fs_inode2v9ses(dentry->d_inode);
356 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
357 return simple_getattr(mnt, dentry, stat);
358
359 fid = v9fs_fid_lookup(dentry);
360 if (IS_ERR(fid))
361 return PTR_ERR(fid);
362
363 /* Ask for all the fields in stat structure. Server will return
364 * whatever it supports
365 */
366
367 st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
368 if (IS_ERR(st))
369 return PTR_ERR(st);
370
371 v9fs_stat2inode_dotl(st, dentry->d_inode);
372 generic_fillattr(dentry->d_inode, stat);
373 /* Change block size to what the server returned */
374 stat->blksize = st->st_blksize;
375
376 kfree(st);
377 return 0;
378}
379
380/**
381 * v9fs_vfs_setattr_dotl - set file metadata
382 * @dentry: file whose metadata to set
383 * @iattr: metadata assignment structure
384 *
385 */
386
387int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
388{
389 int retval;
390 struct v9fs_session_info *v9ses;
391 struct p9_fid *fid;
392 struct p9_iattr_dotl p9attr;
393
394 P9_DPRINTK(P9_DEBUG_VFS, "\n");
395
396 retval = inode_change_ok(dentry->d_inode, iattr);
397 if (retval)
398 return retval;
399
400 p9attr.valid = iattr->ia_valid;
401 p9attr.mode = iattr->ia_mode;
402 p9attr.uid = iattr->ia_uid;
403 p9attr.gid = iattr->ia_gid;
404 p9attr.size = iattr->ia_size;
405 p9attr.atime_sec = iattr->ia_atime.tv_sec;
406 p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
407 p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
408 p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
409
410 retval = -EPERM;
411 v9ses = v9fs_inode2v9ses(dentry->d_inode);
412 fid = v9fs_fid_lookup(dentry);
413 if (IS_ERR(fid))
414 return PTR_ERR(fid);
415
416 retval = p9_client_setattr(fid, &p9attr);
417 if (retval < 0)
418 return retval;
419
420 if ((iattr->ia_valid & ATTR_SIZE) &&
421 iattr->ia_size != i_size_read(dentry->d_inode)) {
422 retval = vmtruncate(dentry->d_inode, iattr->ia_size);
423 if (retval)
424 return retval;
425 }
426
427 setattr_copy(dentry->d_inode, iattr);
428 mark_inode_dirty(dentry->d_inode);
429 if (iattr->ia_valid & ATTR_MODE) {
430 /* We also want to update ACL when we update mode bits */
431 retval = v9fs_acl_chmod(dentry);
432 if (retval < 0)
433 return retval;
434 }
435 return 0;
436}
437
438/**
439 * v9fs_stat2inode_dotl - populate an inode structure with stat info
440 * @stat: stat structure
441 * @inode: inode to populate
442 * @sb: superblock of filesystem
443 *
444 */
445
446void
447v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode)
448{
449
450 if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) {
451 inode->i_atime.tv_sec = stat->st_atime_sec;
452 inode->i_atime.tv_nsec = stat->st_atime_nsec;
453 inode->i_mtime.tv_sec = stat->st_mtime_sec;
454 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
455 inode->i_ctime.tv_sec = stat->st_ctime_sec;
456 inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
457 inode->i_uid = stat->st_uid;
458 inode->i_gid = stat->st_gid;
459 inode->i_nlink = stat->st_nlink;
460 inode->i_mode = stat->st_mode;
461 inode->i_rdev = new_decode_dev(stat->st_rdev);
462
463 if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode)))
464 init_special_inode(inode, inode->i_mode, inode->i_rdev);
465
466 i_size_write(inode, stat->st_size);
467 inode->i_blocks = stat->st_blocks;
468 } else {
469 if (stat->st_result_mask & P9_STATS_ATIME) {
470 inode->i_atime.tv_sec = stat->st_atime_sec;
471 inode->i_atime.tv_nsec = stat->st_atime_nsec;
472 }
473 if (stat->st_result_mask & P9_STATS_MTIME) {
474 inode->i_mtime.tv_sec = stat->st_mtime_sec;
475 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
476 }
477 if (stat->st_result_mask & P9_STATS_CTIME) {
478 inode->i_ctime.tv_sec = stat->st_ctime_sec;
479 inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
480 }
481 if (stat->st_result_mask & P9_STATS_UID)
482 inode->i_uid = stat->st_uid;
483 if (stat->st_result_mask & P9_STATS_GID)
484 inode->i_gid = stat->st_gid;
485 if (stat->st_result_mask & P9_STATS_NLINK)
486 inode->i_nlink = stat->st_nlink;
487 if (stat->st_result_mask & P9_STATS_MODE) {
488 inode->i_mode = stat->st_mode;
489 if ((S_ISBLK(inode->i_mode)) ||
490 (S_ISCHR(inode->i_mode)))
491 init_special_inode(inode, inode->i_mode,
492 inode->i_rdev);
493 }
494 if (stat->st_result_mask & P9_STATS_RDEV)
495 inode->i_rdev = new_decode_dev(stat->st_rdev);
496 if (stat->st_result_mask & P9_STATS_SIZE)
497 i_size_write(inode, stat->st_size);
498 if (stat->st_result_mask & P9_STATS_BLOCKS)
499 inode->i_blocks = stat->st_blocks;
500 }
501 if (stat->st_result_mask & P9_STATS_GEN)
502 inode->i_generation = stat->st_gen;
503
504 /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION
505 * because the inode structure does not have fields for them.
506 */
507}
508
509static int
510v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
511 const char *symname)
512{
513 struct v9fs_session_info *v9ses;
514 struct p9_fid *dfid;
515 struct p9_fid *fid = NULL;
516 struct inode *inode;
517 struct p9_qid qid;
518 char *name;
519 int err;
520 gid_t gid;
521
522 name = (char *) dentry->d_name.name;
523 P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_symlink_dotl : %lu,%s,%s\n",
524 dir->i_ino, name, symname);
525 v9ses = v9fs_inode2v9ses(dir);
526
527 dfid = v9fs_fid_lookup(dentry->d_parent);
528 if (IS_ERR(dfid)) {
529 err = PTR_ERR(dfid);
530 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
531 return err;
532 }
533
534 gid = v9fs_get_fsgid_for_create(dir);
535
536 /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */
537 err = p9_client_symlink(dfid, name, (char *)symname, gid, &qid);
538
539 if (err < 0) {
540 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err);
541 goto error;
542 }
543
544 if (v9ses->cache) {
545 /* Now walk from the parent so we can get an unopened fid. */
546 fid = p9_client_walk(dfid, 1, &name, 1);
547 if (IS_ERR(fid)) {
548 err = PTR_ERR(fid);
549 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
550 err);
551 fid = NULL;
552 goto error;
553 }
554
555 /* instantiate inode and assign the unopened fid to dentry */
556 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
557 if (IS_ERR(inode)) {
558 err = PTR_ERR(inode);
559 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
560 err);
561 goto error;
562 }
563 d_set_d_op(dentry, &v9fs_cached_dentry_operations);
564 d_instantiate(dentry, inode);
565 err = v9fs_fid_add(dentry, fid);
566 if (err < 0)
567 goto error;
568 fid = NULL;
569 } else {
570 /* Not in cached mode. No need to populate inode with stat */
571 inode = v9fs_get_inode(dir->i_sb, S_IFLNK);
572 if (IS_ERR(inode)) {
573 err = PTR_ERR(inode);
574 goto error;
575 }
576 d_set_d_op(dentry, &v9fs_dentry_operations);
577 d_instantiate(dentry, inode);
578 }
579
580error:
581 if (fid)
582 p9_client_clunk(fid);
583
584 return err;
585}
586
587/**
588 * v9fs_vfs_link_dotl - create a hardlink for dotl
589 * @old_dentry: dentry for file to link to
590 * @dir: inode destination for new link
591 * @dentry: dentry for link
592 *
593 */
594
595static int
596v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
597 struct dentry *dentry)
598{
599 int err;
600 struct p9_fid *dfid, *oldfid;
601 char *name;
602 struct v9fs_session_info *v9ses;
603 struct dentry *dir_dentry;
604
605 P9_DPRINTK(P9_DEBUG_VFS, "dir ino: %lu, old_name: %s, new_name: %s\n",
606 dir->i_ino, old_dentry->d_name.name,
607 dentry->d_name.name);
608
609 v9ses = v9fs_inode2v9ses(dir);
610 dir_dentry = v9fs_dentry_from_dir_inode(dir);
611 dfid = v9fs_fid_lookup(dir_dentry);
612 if (IS_ERR(dfid))
613 return PTR_ERR(dfid);
614
615 oldfid = v9fs_fid_lookup(old_dentry);
616 if (IS_ERR(oldfid))
617 return PTR_ERR(oldfid);
618
619 name = (char *) dentry->d_name.name;
620
621 err = p9_client_link(dfid, oldfid, (char *)dentry->d_name.name);
622
623 if (err < 0) {
624 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_link failed %d\n", err);
625 return err;
626 }
627
628 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
629 /* Get the latest stat info from server. */
630 struct p9_fid *fid;
631 struct p9_stat_dotl *st;
632
633 fid = v9fs_fid_lookup(old_dentry);
634 if (IS_ERR(fid))
635 return PTR_ERR(fid);
636
637 st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
638 if (IS_ERR(st))
639 return PTR_ERR(st);
640
641 v9fs_stat2inode_dotl(st, old_dentry->d_inode);
642
643 kfree(st);
644 } else {
645 /* Caching disabled. No need to get upto date stat info.
646 * This dentry will be released immediately. So, just hold the
647 * inode
648 */
649 ihold(old_dentry->d_inode);
650 }
651
652 d_set_d_op(dentry, old_dentry->d_op);
653 d_instantiate(dentry, old_dentry->d_inode);
654
655 return err;
656}
657
658/**
659 * v9fs_vfs_mknod_dotl - create a special file
660 * @dir: inode destination for new link
661 * @dentry: dentry for file
662 * @mode: mode for creation
663 * @rdev: device associated with special file
664 *
665 */
666static int
667v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode,
668 dev_t rdev)
669{
670 int err;
671 char *name;
672 mode_t mode;
673 struct v9fs_session_info *v9ses;
674 struct p9_fid *fid = NULL, *dfid = NULL;
675 struct inode *inode;
676 gid_t gid;
677 struct p9_qid qid;
678 struct dentry *dir_dentry;
679 struct posix_acl *dacl = NULL, *pacl = NULL;
680
681 P9_DPRINTK(P9_DEBUG_VFS,
682 " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
683 dentry->d_name.name, omode, MAJOR(rdev), MINOR(rdev));
684
685 if (!new_valid_dev(rdev))
686 return -EINVAL;
687
688 v9ses = v9fs_inode2v9ses(dir);
689 dir_dentry = v9fs_dentry_from_dir_inode(dir);
690 dfid = v9fs_fid_lookup(dir_dentry);
691 if (IS_ERR(dfid)) {
692 err = PTR_ERR(dfid);
693 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
694 dfid = NULL;
695 goto error;
696 }
697
698 gid = v9fs_get_fsgid_for_create(dir);
699 mode = omode;
700 /* Update mode based on ACL value */
701 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
702 if (err) {
703 P9_DPRINTK(P9_DEBUG_VFS,
704 "Failed to get acl values in mknod %d\n", err);
705 goto error;
706 }
707 name = (char *) dentry->d_name.name;
708
709 err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid);
710 if (err < 0)
711 goto error;
712
713 /* instantiate inode and assign the unopened fid to the dentry */
714 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
715 fid = p9_client_walk(dfid, 1, &name, 1);
716 if (IS_ERR(fid)) {
717 err = PTR_ERR(fid);
718 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
719 err);
720 fid = NULL;
721 goto error;
722 }
723
724 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
725 if (IS_ERR(inode)) {
726 err = PTR_ERR(inode);
727 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
728 err);
729 goto error;
730 }
731 d_set_d_op(dentry, &v9fs_cached_dentry_operations);
732 d_instantiate(dentry, inode);
733 err = v9fs_fid_add(dentry, fid);
734 if (err < 0)
735 goto error;
736 fid = NULL;
737 } else {
738 /*
739 * Not in cached mode. No need to populate inode with stat.
740 * socket syscall returns a fd, so we need instantiate
741 */
742 inode = v9fs_get_inode(dir->i_sb, mode);
743 if (IS_ERR(inode)) {
744 err = PTR_ERR(inode);
745 goto error;
746 }
747 d_set_d_op(dentry, &v9fs_dentry_operations);
748 d_instantiate(dentry, inode);
749 }
750 /* Now set the ACL based on the default value */
751 v9fs_set_create_acl(dentry, dacl, pacl);
752error:
753 if (fid)
754 p9_client_clunk(fid);
755 return err;
756}
757
758static int
759v9fs_vfs_readlink_dotl(struct dentry *dentry, char *buffer, int buflen)
760{
761 int retval;
762 struct p9_fid *fid;
763 char *target = NULL;
764
765 P9_DPRINTK(P9_DEBUG_VFS, " %s\n", dentry->d_name.name);
766 retval = -EPERM;
767 fid = v9fs_fid_lookup(dentry);
768 if (IS_ERR(fid))
769 return PTR_ERR(fid);
770
771 retval = p9_client_readlink(fid, &target);
772 if (retval < 0)
773 return retval;
774
775 strncpy(buffer, target, buflen);
776 P9_DPRINTK(P9_DEBUG_VFS, "%s -> %s\n", dentry->d_name.name, buffer);
777
778 retval = strnlen(buffer, buflen);
779 return retval;
780}
781
782/**
783 * v9fs_vfs_follow_link_dotl - follow a symlink path
784 * @dentry: dentry for symlink
785 * @nd: nameidata
786 *
787 */
788
789static void *
790v9fs_vfs_follow_link_dotl(struct dentry *dentry, struct nameidata *nd)
791{
792 int len = 0;
793 char *link = __getname();
794
795 P9_DPRINTK(P9_DEBUG_VFS, "%s n", dentry->d_name.name);
796
797 if (!link)
798 link = ERR_PTR(-ENOMEM);
799 else {
800 len = v9fs_vfs_readlink_dotl(dentry, link, PATH_MAX);
801 if (len < 0) {
802 __putname(link);
803 link = ERR_PTR(len);
804 } else
805 link[min(len, PATH_MAX-1)] = 0;
806 }
807 nd_set_link(nd, link);
808
809 return NULL;
810}
811
812const struct inode_operations v9fs_dir_inode_operations_dotl = {
813 .create = v9fs_vfs_create_dotl,
814 .lookup = v9fs_vfs_lookup,
815 .link = v9fs_vfs_link_dotl,
816 .symlink = v9fs_vfs_symlink_dotl,
817 .unlink = v9fs_vfs_unlink,
818 .mkdir = v9fs_vfs_mkdir_dotl,
819 .rmdir = v9fs_vfs_rmdir,
820 .mknod = v9fs_vfs_mknod_dotl,
821 .rename = v9fs_vfs_rename,
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 .check_acl = v9fs_check_acl,
829};
830
831const struct inode_operations v9fs_file_inode_operations_dotl = {
832 .getattr = v9fs_vfs_getattr_dotl,
833 .setattr = v9fs_vfs_setattr_dotl,
834 .setxattr = generic_setxattr,
835 .getxattr = generic_getxattr,
836 .removexattr = generic_removexattr,
837 .listxattr = v9fs_listxattr,
838 .check_acl = v9fs_check_acl,
839};
840
841const struct inode_operations v9fs_symlink_inode_operations_dotl = {
842 .readlink = v9fs_vfs_readlink_dotl,
843 .follow_link = v9fs_vfs_follow_link_dotl,
844 .put_link = v9fs_vfs_put_link,
845 .getattr = v9fs_vfs_getattr_dotl,
846 .setattr = v9fs_vfs_setattr_dotl,
847 .setxattr = generic_setxattr,
848 .getxattr = generic_getxattr,
849 .removexattr = generic_removexattr,
850 .listxattr = v9fs_listxattr,
851};