Loading...
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * linux/fs/9p/vfs_inode.c
4 *
5 * This file contains vfs inode ops for the 9P2000 protocol.
6 *
7 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
8 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
9 */
10
11#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12
13#include <linux/module.h>
14#include <linux/errno.h>
15#include <linux/fs.h>
16#include <linux/file.h>
17#include <linux/pagemap.h>
18#include <linux/stat.h>
19#include <linux/string.h>
20#include <linux/inet.h>
21#include <linux/namei.h>
22#include <linux/idr.h>
23#include <linux/sched.h>
24#include <linux/slab.h>
25#include <linux/xattr.h>
26#include <linux/posix_acl.h>
27#include <net/9p/9p.h>
28#include <net/9p/client.h>
29
30#include "v9fs.h"
31#include "v9fs_vfs.h"
32#include "fid.h"
33#include "cache.h"
34#include "xattr.h"
35#include "acl.h"
36
37static const struct inode_operations v9fs_dir_inode_operations;
38static const struct inode_operations v9fs_dir_inode_operations_dotu;
39static const struct inode_operations v9fs_file_inode_operations;
40static const struct inode_operations v9fs_symlink_inode_operations;
41
42/**
43 * unixmode2p9mode - convert unix mode bits to plan 9
44 * @v9ses: v9fs session information
45 * @mode: mode to convert
46 *
47 */
48
49static u32 unixmode2p9mode(struct v9fs_session_info *v9ses, umode_t mode)
50{
51 int res;
52 res = mode & 0777;
53 if (S_ISDIR(mode))
54 res |= P9_DMDIR;
55 if (v9fs_proto_dotu(v9ses)) {
56 if (v9ses->nodev == 0) {
57 if (S_ISSOCK(mode))
58 res |= P9_DMSOCKET;
59 if (S_ISFIFO(mode))
60 res |= P9_DMNAMEDPIPE;
61 if (S_ISBLK(mode))
62 res |= P9_DMDEVICE;
63 if (S_ISCHR(mode))
64 res |= P9_DMDEVICE;
65 }
66
67 if ((mode & S_ISUID) == S_ISUID)
68 res |= P9_DMSETUID;
69 if ((mode & S_ISGID) == S_ISGID)
70 res |= P9_DMSETGID;
71 if ((mode & S_ISVTX) == S_ISVTX)
72 res |= P9_DMSETVTX;
73 }
74 return res;
75}
76
77/**
78 * p9mode2perm- convert plan9 mode bits to unix permission bits
79 * @v9ses: v9fs session information
80 * @stat: p9_wstat from which mode need to be derived
81 *
82 */
83static int p9mode2perm(struct v9fs_session_info *v9ses,
84 struct p9_wstat *stat)
85{
86 int res;
87 int mode = stat->mode;
88
89 res = mode & S_IALLUGO;
90 if (v9fs_proto_dotu(v9ses)) {
91 if ((mode & P9_DMSETUID) == P9_DMSETUID)
92 res |= S_ISUID;
93
94 if ((mode & P9_DMSETGID) == P9_DMSETGID)
95 res |= S_ISGID;
96
97 if ((mode & P9_DMSETVTX) == P9_DMSETVTX)
98 res |= S_ISVTX;
99 }
100 return res;
101}
102
103/**
104 * p9mode2unixmode- convert plan9 mode bits to unix mode bits
105 * @v9ses: v9fs session information
106 * @stat: p9_wstat from which mode need to be derived
107 * @rdev: major number, minor number in case of device files.
108 *
109 */
110static umode_t p9mode2unixmode(struct v9fs_session_info *v9ses,
111 struct p9_wstat *stat, dev_t *rdev)
112{
113 int res;
114 u32 mode = stat->mode;
115
116 *rdev = 0;
117 res = p9mode2perm(v9ses, stat);
118
119 if ((mode & P9_DMDIR) == P9_DMDIR)
120 res |= S_IFDIR;
121 else if ((mode & P9_DMSYMLINK) && (v9fs_proto_dotu(v9ses)))
122 res |= S_IFLNK;
123 else if ((mode & P9_DMSOCKET) && (v9fs_proto_dotu(v9ses))
124 && (v9ses->nodev == 0))
125 res |= S_IFSOCK;
126 else if ((mode & P9_DMNAMEDPIPE) && (v9fs_proto_dotu(v9ses))
127 && (v9ses->nodev == 0))
128 res |= S_IFIFO;
129 else if ((mode & P9_DMDEVICE) && (v9fs_proto_dotu(v9ses))
130 && (v9ses->nodev == 0)) {
131 char type = 0, ext[32];
132 int major = -1, minor = -1;
133
134 strlcpy(ext, stat->extension, sizeof(ext));
135 sscanf(ext, "%c %i %i", &type, &major, &minor);
136 switch (type) {
137 case 'c':
138 res |= S_IFCHR;
139 break;
140 case 'b':
141 res |= S_IFBLK;
142 break;
143 default:
144 p9_debug(P9_DEBUG_ERROR, "Unknown special type %c %s\n",
145 type, stat->extension);
146 }
147 *rdev = MKDEV(major, minor);
148 } else
149 res |= S_IFREG;
150
151 return res;
152}
153
154/**
155 * v9fs_uflags2omode- convert posix open flags to plan 9 mode bits
156 * @uflags: flags to convert
157 * @extended: if .u extensions are active
158 */
159
160int v9fs_uflags2omode(int uflags, int extended)
161{
162 int ret;
163
164 ret = 0;
165 switch (uflags&3) {
166 default:
167 case O_RDONLY:
168 ret = P9_OREAD;
169 break;
170
171 case O_WRONLY:
172 ret = P9_OWRITE;
173 break;
174
175 case O_RDWR:
176 ret = P9_ORDWR;
177 break;
178 }
179
180 if (extended) {
181 if (uflags & O_EXCL)
182 ret |= P9_OEXCL;
183
184 if (uflags & O_APPEND)
185 ret |= P9_OAPPEND;
186 }
187
188 return ret;
189}
190
191/**
192 * v9fs_blank_wstat - helper function to setup a 9P stat structure
193 * @wstat: structure to initialize
194 *
195 */
196
197void
198v9fs_blank_wstat(struct p9_wstat *wstat)
199{
200 wstat->type = ~0;
201 wstat->dev = ~0;
202 wstat->qid.type = ~0;
203 wstat->qid.version = ~0;
204 *((long long *)&wstat->qid.path) = ~0;
205 wstat->mode = ~0;
206 wstat->atime = ~0;
207 wstat->mtime = ~0;
208 wstat->length = ~0;
209 wstat->name = NULL;
210 wstat->uid = NULL;
211 wstat->gid = NULL;
212 wstat->muid = NULL;
213 wstat->n_uid = INVALID_UID;
214 wstat->n_gid = INVALID_GID;
215 wstat->n_muid = INVALID_UID;
216 wstat->extension = NULL;
217}
218
219/**
220 * v9fs_alloc_inode - helper function to allocate an inode
221 *
222 */
223struct inode *v9fs_alloc_inode(struct super_block *sb)
224{
225 struct v9fs_inode *v9inode;
226 v9inode = kmem_cache_alloc(v9fs_inode_cache, GFP_KERNEL);
227 if (!v9inode)
228 return NULL;
229#ifdef CONFIG_9P_FSCACHE
230 v9inode->fscache = NULL;
231 mutex_init(&v9inode->fscache_lock);
232#endif
233 v9inode->writeback_fid = NULL;
234 v9inode->cache_validity = 0;
235 mutex_init(&v9inode->v_mutex);
236 return &v9inode->vfs_inode;
237}
238
239/**
240 * v9fs_free_inode - destroy an inode
241 *
242 */
243
244void v9fs_free_inode(struct inode *inode)
245{
246 kmem_cache_free(v9fs_inode_cache, V9FS_I(inode));
247}
248
249int v9fs_init_inode(struct v9fs_session_info *v9ses,
250 struct inode *inode, umode_t mode, dev_t rdev)
251{
252 int err = 0;
253
254 inode_init_owner(&init_user_ns,inode, NULL, mode);
255 inode->i_blocks = 0;
256 inode->i_rdev = rdev;
257 inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
258 inode->i_mapping->a_ops = &v9fs_addr_operations;
259 inode->i_private = NULL;
260
261 switch (mode & S_IFMT) {
262 case S_IFIFO:
263 case S_IFBLK:
264 case S_IFCHR:
265 case S_IFSOCK:
266 if (v9fs_proto_dotl(v9ses)) {
267 inode->i_op = &v9fs_file_inode_operations_dotl;
268 } else if (v9fs_proto_dotu(v9ses)) {
269 inode->i_op = &v9fs_file_inode_operations;
270 } else {
271 p9_debug(P9_DEBUG_ERROR,
272 "special files without extended mode\n");
273 err = -EINVAL;
274 goto error;
275 }
276 init_special_inode(inode, inode->i_mode, inode->i_rdev);
277 break;
278 case S_IFREG:
279 if (v9fs_proto_dotl(v9ses)) {
280 inode->i_op = &v9fs_file_inode_operations_dotl;
281 if (v9ses->cache == CACHE_LOOSE ||
282 v9ses->cache == CACHE_FSCACHE)
283 inode->i_fop =
284 &v9fs_cached_file_operations_dotl;
285 else if (v9ses->cache == CACHE_MMAP)
286 inode->i_fop = &v9fs_mmap_file_operations_dotl;
287 else
288 inode->i_fop = &v9fs_file_operations_dotl;
289 } else {
290 inode->i_op = &v9fs_file_inode_operations;
291 if (v9ses->cache == CACHE_LOOSE ||
292 v9ses->cache == CACHE_FSCACHE)
293 inode->i_fop =
294 &v9fs_cached_file_operations;
295 else if (v9ses->cache == CACHE_MMAP)
296 inode->i_fop = &v9fs_mmap_file_operations;
297 else
298 inode->i_fop = &v9fs_file_operations;
299 }
300
301 break;
302 case S_IFLNK:
303 if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)) {
304 p9_debug(P9_DEBUG_ERROR,
305 "extended modes used with legacy protocol\n");
306 err = -EINVAL;
307 goto error;
308 }
309
310 if (v9fs_proto_dotl(v9ses))
311 inode->i_op = &v9fs_symlink_inode_operations_dotl;
312 else
313 inode->i_op = &v9fs_symlink_inode_operations;
314
315 break;
316 case S_IFDIR:
317 inc_nlink(inode);
318 if (v9fs_proto_dotl(v9ses))
319 inode->i_op = &v9fs_dir_inode_operations_dotl;
320 else if (v9fs_proto_dotu(v9ses))
321 inode->i_op = &v9fs_dir_inode_operations_dotu;
322 else
323 inode->i_op = &v9fs_dir_inode_operations;
324
325 if (v9fs_proto_dotl(v9ses))
326 inode->i_fop = &v9fs_dir_operations_dotl;
327 else
328 inode->i_fop = &v9fs_dir_operations;
329
330 break;
331 default:
332 p9_debug(P9_DEBUG_ERROR, "BAD mode 0x%hx S_IFMT 0x%x\n",
333 mode, mode & S_IFMT);
334 err = -EINVAL;
335 goto error;
336 }
337error:
338 return err;
339
340}
341
342/**
343 * v9fs_get_inode - helper function to setup an inode
344 * @sb: superblock
345 * @mode: mode to setup inode with
346 *
347 */
348
349struct inode *v9fs_get_inode(struct super_block *sb, umode_t mode, dev_t rdev)
350{
351 int err;
352 struct inode *inode;
353 struct v9fs_session_info *v9ses = sb->s_fs_info;
354
355 p9_debug(P9_DEBUG_VFS, "super block: %p mode: %ho\n", sb, mode);
356
357 inode = new_inode(sb);
358 if (!inode) {
359 pr_warn("%s (%d): Problem allocating inode\n",
360 __func__, task_pid_nr(current));
361 return ERR_PTR(-ENOMEM);
362 }
363 err = v9fs_init_inode(v9ses, inode, mode, rdev);
364 if (err) {
365 iput(inode);
366 return ERR_PTR(err);
367 }
368 return inode;
369}
370
371/**
372 * v9fs_clear_inode - release an inode
373 * @inode: inode to release
374 *
375 */
376void v9fs_evict_inode(struct inode *inode)
377{
378 struct v9fs_inode *v9inode = V9FS_I(inode);
379
380 truncate_inode_pages_final(&inode->i_data);
381 clear_inode(inode);
382 filemap_fdatawrite(&inode->i_data);
383
384 v9fs_cache_inode_put_cookie(inode);
385 /* clunk the fid stashed in writeback_fid */
386 if (v9inode->writeback_fid) {
387 p9_client_clunk(v9inode->writeback_fid);
388 v9inode->writeback_fid = NULL;
389 }
390}
391
392static int v9fs_test_inode(struct inode *inode, void *data)
393{
394 int umode;
395 dev_t rdev;
396 struct v9fs_inode *v9inode = V9FS_I(inode);
397 struct p9_wstat *st = (struct p9_wstat *)data;
398 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
399
400 umode = p9mode2unixmode(v9ses, st, &rdev);
401 /* don't match inode of different type */
402 if (inode_wrong_type(inode, umode))
403 return 0;
404
405 /* compare qid details */
406 if (memcmp(&v9inode->qid.version,
407 &st->qid.version, sizeof(v9inode->qid.version)))
408 return 0;
409
410 if (v9inode->qid.type != st->qid.type)
411 return 0;
412
413 if (v9inode->qid.path != st->qid.path)
414 return 0;
415 return 1;
416}
417
418static int v9fs_test_new_inode(struct inode *inode, void *data)
419{
420 return 0;
421}
422
423static int v9fs_set_inode(struct inode *inode, void *data)
424{
425 struct v9fs_inode *v9inode = V9FS_I(inode);
426 struct p9_wstat *st = (struct p9_wstat *)data;
427
428 memcpy(&v9inode->qid, &st->qid, sizeof(st->qid));
429 return 0;
430}
431
432static struct inode *v9fs_qid_iget(struct super_block *sb,
433 struct p9_qid *qid,
434 struct p9_wstat *st,
435 int new)
436{
437 dev_t rdev;
438 int retval;
439 umode_t umode;
440 unsigned long i_ino;
441 struct inode *inode;
442 struct v9fs_session_info *v9ses = sb->s_fs_info;
443 int (*test)(struct inode *, void *);
444
445 if (new)
446 test = v9fs_test_new_inode;
447 else
448 test = v9fs_test_inode;
449
450 i_ino = v9fs_qid2ino(qid);
451 inode = iget5_locked(sb, i_ino, test, v9fs_set_inode, st);
452 if (!inode)
453 return ERR_PTR(-ENOMEM);
454 if (!(inode->i_state & I_NEW))
455 return inode;
456 /*
457 * initialize the inode with the stat info
458 * FIXME!! we may need support for stale inodes
459 * later.
460 */
461 inode->i_ino = i_ino;
462 umode = p9mode2unixmode(v9ses, st, &rdev);
463 retval = v9fs_init_inode(v9ses, inode, umode, rdev);
464 if (retval)
465 goto error;
466
467 v9fs_stat2inode(st, inode, sb, 0);
468 v9fs_cache_inode_get_cookie(inode);
469 unlock_new_inode(inode);
470 return inode;
471error:
472 iget_failed(inode);
473 return ERR_PTR(retval);
474
475}
476
477struct inode *
478v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
479 struct super_block *sb, int new)
480{
481 struct p9_wstat *st;
482 struct inode *inode = NULL;
483
484 st = p9_client_stat(fid);
485 if (IS_ERR(st))
486 return ERR_CAST(st);
487
488 inode = v9fs_qid_iget(sb, &st->qid, st, new);
489 p9stat_free(st);
490 kfree(st);
491 return inode;
492}
493
494/**
495 * v9fs_at_to_dotl_flags- convert Linux specific AT flags to
496 * plan 9 AT flag.
497 * @flags: flags to convert
498 */
499static int v9fs_at_to_dotl_flags(int flags)
500{
501 int rflags = 0;
502 if (flags & AT_REMOVEDIR)
503 rflags |= P9_DOTL_AT_REMOVEDIR;
504 return rflags;
505}
506
507/**
508 * v9fs_dec_count - helper functon to drop i_nlink.
509 *
510 * If a directory had nlink <= 2 (including . and ..), then we should not drop
511 * the link count, which indicates the underlying exported fs doesn't maintain
512 * nlink accurately. e.g.
513 * - overlayfs sets nlink to 1 for merged dir
514 * - ext4 (with dir_nlink feature enabled) sets nlink to 1 if a dir has more
515 * than EXT4_LINK_MAX (65000) links.
516 *
517 * @inode: inode whose nlink is being dropped
518 */
519static void v9fs_dec_count(struct inode *inode)
520{
521 if (!S_ISDIR(inode->i_mode) || inode->i_nlink > 2)
522 drop_nlink(inode);
523}
524
525/**
526 * v9fs_remove - helper function to remove files and directories
527 * @dir: directory inode that is being deleted
528 * @dentry: dentry that is being deleted
529 * @flags: removing a directory
530 *
531 */
532
533static int v9fs_remove(struct inode *dir, struct dentry *dentry, int flags)
534{
535 struct inode *inode;
536 int retval = -EOPNOTSUPP;
537 struct p9_fid *v9fid, *dfid;
538 struct v9fs_session_info *v9ses;
539
540 p9_debug(P9_DEBUG_VFS, "inode: %p dentry: %p rmdir: %x\n",
541 dir, dentry, flags);
542
543 v9ses = v9fs_inode2v9ses(dir);
544 inode = d_inode(dentry);
545 dfid = v9fs_parent_fid(dentry);
546 if (IS_ERR(dfid)) {
547 retval = PTR_ERR(dfid);
548 p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", retval);
549 return retval;
550 }
551 if (v9fs_proto_dotl(v9ses))
552 retval = p9_client_unlinkat(dfid, dentry->d_name.name,
553 v9fs_at_to_dotl_flags(flags));
554 p9_client_clunk(dfid);
555 if (retval == -EOPNOTSUPP) {
556 /* Try the one based on path */
557 v9fid = v9fs_fid_clone(dentry);
558 if (IS_ERR(v9fid))
559 return PTR_ERR(v9fid);
560 retval = p9_client_remove(v9fid);
561 }
562 if (!retval) {
563 /*
564 * directories on unlink should have zero
565 * link count
566 */
567 if (flags & AT_REMOVEDIR) {
568 clear_nlink(inode);
569 v9fs_dec_count(dir);
570 } else
571 v9fs_dec_count(inode);
572
573 v9fs_invalidate_inode_attr(inode);
574 v9fs_invalidate_inode_attr(dir);
575
576 /* invalidate all fids associated with dentry */
577 /* NOTE: This will not include open fids */
578 dentry->d_op->d_release(dentry);
579 }
580 return retval;
581}
582
583/**
584 * v9fs_create - Create a file
585 * @v9ses: session information
586 * @dir: directory that dentry is being created in
587 * @dentry: dentry that is being created
588 * @extension: 9p2000.u extension string to support devices, etc.
589 * @perm: create permissions
590 * @mode: open mode
591 *
592 */
593static struct p9_fid *
594v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
595 struct dentry *dentry, char *extension, u32 perm, u8 mode)
596{
597 int err;
598 const unsigned char *name;
599 struct p9_fid *dfid, *ofid = NULL, *fid = NULL;
600 struct inode *inode;
601
602 p9_debug(P9_DEBUG_VFS, "name %pd\n", dentry);
603
604 err = 0;
605 name = dentry->d_name.name;
606 dfid = v9fs_parent_fid(dentry);
607 if (IS_ERR(dfid)) {
608 err = PTR_ERR(dfid);
609 p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
610 return ERR_PTR(err);
611 }
612
613 /* clone a fid to use for creation */
614 ofid = clone_fid(dfid);
615 if (IS_ERR(ofid)) {
616 err = PTR_ERR(ofid);
617 p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
618 p9_client_clunk(dfid);
619 return ERR_PTR(err);
620 }
621
622 err = p9_client_fcreate(ofid, name, perm, mode, extension);
623 if (err < 0) {
624 p9_debug(P9_DEBUG_VFS, "p9_client_fcreate failed %d\n", err);
625 p9_client_clunk(dfid);
626 goto error;
627 }
628
629 if (!(perm & P9_DMLINK)) {
630 /* now walk from the parent so we can get unopened fid */
631 fid = p9_client_walk(dfid, 1, &name, 1);
632 if (IS_ERR(fid)) {
633 err = PTR_ERR(fid);
634 p9_debug(P9_DEBUG_VFS,
635 "p9_client_walk failed %d\n", err);
636 fid = NULL;
637 p9_client_clunk(dfid);
638 goto error;
639 }
640 /*
641 * instantiate inode and assign the unopened fid to the dentry
642 */
643 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
644 if (IS_ERR(inode)) {
645 err = PTR_ERR(inode);
646 p9_debug(P9_DEBUG_VFS,
647 "inode creation failed %d\n", err);
648 p9_client_clunk(dfid);
649 goto error;
650 }
651 v9fs_fid_add(dentry, fid);
652 d_instantiate(dentry, inode);
653 }
654 p9_client_clunk(dfid);
655 return ofid;
656error:
657 if (ofid)
658 p9_client_clunk(ofid);
659
660 if (fid)
661 p9_client_clunk(fid);
662
663 return ERR_PTR(err);
664}
665
666/**
667 * v9fs_vfs_create - VFS hook to create a regular file
668 *
669 * open(.., O_CREAT) is handled in v9fs_vfs_atomic_open(). This is only called
670 * for mknod(2).
671 *
672 * @dir: directory inode that is being created
673 * @dentry: dentry that is being deleted
674 * @mode: create permissions
675 *
676 */
677
678static int
679v9fs_vfs_create(struct user_namespace *mnt_userns, struct inode *dir,
680 struct dentry *dentry, umode_t mode, bool excl)
681{
682 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
683 u32 perm = unixmode2p9mode(v9ses, mode);
684 struct p9_fid *fid;
685
686 /* P9_OEXCL? */
687 fid = v9fs_create(v9ses, dir, dentry, NULL, perm, P9_ORDWR);
688 if (IS_ERR(fid))
689 return PTR_ERR(fid);
690
691 v9fs_invalidate_inode_attr(dir);
692 p9_client_clunk(fid);
693
694 return 0;
695}
696
697/**
698 * v9fs_vfs_mkdir - VFS mkdir hook to create a directory
699 * @dir: inode that is being unlinked
700 * @dentry: dentry that is being unlinked
701 * @mode: mode for new directory
702 *
703 */
704
705static int v9fs_vfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
706 struct dentry *dentry, umode_t mode)
707{
708 int err;
709 u32 perm;
710 struct p9_fid *fid;
711 struct v9fs_session_info *v9ses;
712
713 p9_debug(P9_DEBUG_VFS, "name %pd\n", dentry);
714 err = 0;
715 v9ses = v9fs_inode2v9ses(dir);
716 perm = unixmode2p9mode(v9ses, mode | S_IFDIR);
717 fid = v9fs_create(v9ses, dir, dentry, NULL, perm, P9_OREAD);
718 if (IS_ERR(fid)) {
719 err = PTR_ERR(fid);
720 fid = NULL;
721 } else {
722 inc_nlink(dir);
723 v9fs_invalidate_inode_attr(dir);
724 }
725
726 if (fid)
727 p9_client_clunk(fid);
728
729 return err;
730}
731
732/**
733 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
734 * @dir: inode that is being walked from
735 * @dentry: dentry that is being walked to?
736 * @flags: lookup flags (unused)
737 *
738 */
739
740struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
741 unsigned int flags)
742{
743 struct dentry *res;
744 struct v9fs_session_info *v9ses;
745 struct p9_fid *dfid, *fid;
746 struct inode *inode;
747 const unsigned char *name;
748
749 p9_debug(P9_DEBUG_VFS, "dir: %p dentry: (%pd) %p flags: %x\n",
750 dir, dentry, dentry, flags);
751
752 if (dentry->d_name.len > NAME_MAX)
753 return ERR_PTR(-ENAMETOOLONG);
754
755 v9ses = v9fs_inode2v9ses(dir);
756 /* We can walk d_parent because we hold the dir->i_mutex */
757 dfid = v9fs_parent_fid(dentry);
758 if (IS_ERR(dfid))
759 return ERR_CAST(dfid);
760
761 /*
762 * Make sure we don't use a wrong inode due to parallel
763 * unlink. For cached mode create calls request for new
764 * inode. But with cache disabled, lookup should do this.
765 */
766 name = dentry->d_name.name;
767 fid = p9_client_walk(dfid, 1, &name, 1);
768 p9_client_clunk(dfid);
769 if (fid == ERR_PTR(-ENOENT))
770 inode = NULL;
771 else if (IS_ERR(fid))
772 inode = ERR_CAST(fid);
773 else if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
774 inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
775 else
776 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
777 /*
778 * If we had a rename on the server and a parallel lookup
779 * for the new name, then make sure we instantiate with
780 * the new name. ie look up for a/b, while on server somebody
781 * moved b under k and client parallely did a lookup for
782 * k/b.
783 */
784 res = d_splice_alias(inode, dentry);
785 if (!IS_ERR(fid)) {
786 if (!res)
787 v9fs_fid_add(dentry, fid);
788 else if (!IS_ERR(res))
789 v9fs_fid_add(res, fid);
790 else
791 p9_client_clunk(fid);
792 }
793 return res;
794}
795
796static int
797v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
798 struct file *file, unsigned flags, umode_t mode)
799{
800 int err;
801 u32 perm;
802 struct v9fs_inode *v9inode;
803 struct v9fs_session_info *v9ses;
804 struct p9_fid *fid, *inode_fid;
805 struct dentry *res = NULL;
806 struct inode *inode;
807
808 if (d_in_lookup(dentry)) {
809 res = v9fs_vfs_lookup(dir, dentry, 0);
810 if (IS_ERR(res))
811 return PTR_ERR(res);
812
813 if (res)
814 dentry = res;
815 }
816
817 /* Only creates */
818 if (!(flags & O_CREAT) || d_really_is_positive(dentry))
819 return finish_no_open(file, res);
820
821 err = 0;
822
823 v9ses = v9fs_inode2v9ses(dir);
824 perm = unixmode2p9mode(v9ses, mode);
825 fid = v9fs_create(v9ses, dir, dentry, NULL, perm,
826 v9fs_uflags2omode(flags,
827 v9fs_proto_dotu(v9ses)));
828 if (IS_ERR(fid)) {
829 err = PTR_ERR(fid);
830 fid = NULL;
831 goto error;
832 }
833
834 v9fs_invalidate_inode_attr(dir);
835 inode = d_inode(dentry);
836 v9inode = V9FS_I(inode);
837 mutex_lock(&v9inode->v_mutex);
838 if ((v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) &&
839 !v9inode->writeback_fid &&
840 ((flags & O_ACCMODE) != O_RDONLY)) {
841 /*
842 * clone a fid and add it to writeback_fid
843 * we do it during open time instead of
844 * page dirty time via write_begin/page_mkwrite
845 * because we want write after unlink usecase
846 * to work.
847 */
848 inode_fid = v9fs_writeback_fid(dentry);
849 if (IS_ERR(inode_fid)) {
850 err = PTR_ERR(inode_fid);
851 mutex_unlock(&v9inode->v_mutex);
852 goto error;
853 }
854 v9inode->writeback_fid = (void *) inode_fid;
855 }
856 mutex_unlock(&v9inode->v_mutex);
857 err = finish_open(file, dentry, generic_file_open);
858 if (err)
859 goto error;
860
861 file->private_data = fid;
862 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
863 v9fs_cache_inode_set_cookie(d_inode(dentry), file);
864 v9fs_open_fid_add(inode, fid);
865
866 file->f_mode |= FMODE_CREATED;
867out:
868 dput(res);
869 return err;
870
871error:
872 if (fid)
873 p9_client_clunk(fid);
874 goto out;
875}
876
877/**
878 * v9fs_vfs_unlink - VFS unlink hook to delete an inode
879 * @i: inode that is being unlinked
880 * @d: dentry that is being unlinked
881 *
882 */
883
884int v9fs_vfs_unlink(struct inode *i, struct dentry *d)
885{
886 return v9fs_remove(i, d, 0);
887}
888
889/**
890 * v9fs_vfs_rmdir - VFS unlink hook to delete a directory
891 * @i: inode that is being unlinked
892 * @d: dentry that is being unlinked
893 *
894 */
895
896int v9fs_vfs_rmdir(struct inode *i, struct dentry *d)
897{
898 return v9fs_remove(i, d, AT_REMOVEDIR);
899}
900
901/**
902 * v9fs_vfs_rename - VFS hook to rename an inode
903 * @old_dir: old dir inode
904 * @old_dentry: old dentry
905 * @new_dir: new dir inode
906 * @new_dentry: new dentry
907 *
908 */
909
910int
911v9fs_vfs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
912 struct dentry *old_dentry, struct inode *new_dir,
913 struct dentry *new_dentry, unsigned int flags)
914{
915 int retval;
916 struct inode *old_inode;
917 struct inode *new_inode;
918 struct v9fs_session_info *v9ses;
919 struct p9_fid *oldfid, *dfid;
920 struct p9_fid *olddirfid;
921 struct p9_fid *newdirfid;
922 struct p9_wstat wstat;
923
924 if (flags)
925 return -EINVAL;
926
927 p9_debug(P9_DEBUG_VFS, "\n");
928 retval = 0;
929 old_inode = d_inode(old_dentry);
930 new_inode = d_inode(new_dentry);
931 v9ses = v9fs_inode2v9ses(old_inode);
932 oldfid = v9fs_fid_lookup(old_dentry);
933 if (IS_ERR(oldfid))
934 return PTR_ERR(oldfid);
935
936 dfid = v9fs_parent_fid(old_dentry);
937 olddirfid = clone_fid(dfid);
938 if (dfid && !IS_ERR(dfid))
939 p9_client_clunk(dfid);
940
941 if (IS_ERR(olddirfid)) {
942 retval = PTR_ERR(olddirfid);
943 goto done;
944 }
945
946 dfid = v9fs_parent_fid(new_dentry);
947 newdirfid = clone_fid(dfid);
948 p9_client_clunk(dfid);
949
950 if (IS_ERR(newdirfid)) {
951 retval = PTR_ERR(newdirfid);
952 goto clunk_olddir;
953 }
954
955 down_write(&v9ses->rename_sem);
956 if (v9fs_proto_dotl(v9ses)) {
957 retval = p9_client_renameat(olddirfid, old_dentry->d_name.name,
958 newdirfid, new_dentry->d_name.name);
959 if (retval == -EOPNOTSUPP)
960 retval = p9_client_rename(oldfid, newdirfid,
961 new_dentry->d_name.name);
962 if (retval != -EOPNOTSUPP)
963 goto clunk_newdir;
964 }
965 if (old_dentry->d_parent != new_dentry->d_parent) {
966 /*
967 * 9P .u can only handle file rename in the same directory
968 */
969
970 p9_debug(P9_DEBUG_ERROR, "old dir and new dir are different\n");
971 retval = -EXDEV;
972 goto clunk_newdir;
973 }
974 v9fs_blank_wstat(&wstat);
975 wstat.muid = v9ses->uname;
976 wstat.name = new_dentry->d_name.name;
977 retval = p9_client_wstat(oldfid, &wstat);
978
979clunk_newdir:
980 if (!retval) {
981 if (new_inode) {
982 if (S_ISDIR(new_inode->i_mode))
983 clear_nlink(new_inode);
984 else
985 v9fs_dec_count(new_inode);
986 }
987 if (S_ISDIR(old_inode->i_mode)) {
988 if (!new_inode)
989 inc_nlink(new_dir);
990 v9fs_dec_count(old_dir);
991 }
992 v9fs_invalidate_inode_attr(old_inode);
993 v9fs_invalidate_inode_attr(old_dir);
994 v9fs_invalidate_inode_attr(new_dir);
995
996 /* successful rename */
997 d_move(old_dentry, new_dentry);
998 }
999 up_write(&v9ses->rename_sem);
1000 p9_client_clunk(newdirfid);
1001
1002clunk_olddir:
1003 p9_client_clunk(olddirfid);
1004
1005done:
1006 p9_client_clunk(oldfid);
1007 return retval;
1008}
1009
1010/**
1011 * v9fs_vfs_getattr - retrieve file metadata
1012 * @path: Object to query
1013 * @stat: metadata structure to populate
1014 * @request_mask: Mask of STATX_xxx flags indicating the caller's interests
1015 * @flags: AT_STATX_xxx setting
1016 *
1017 */
1018
1019static int
1020v9fs_vfs_getattr(struct user_namespace *mnt_userns, const struct path *path,
1021 struct kstat *stat, u32 request_mask, unsigned int flags)
1022{
1023 struct dentry *dentry = path->dentry;
1024 struct v9fs_session_info *v9ses;
1025 struct p9_fid *fid;
1026 struct p9_wstat *st;
1027
1028 p9_debug(P9_DEBUG_VFS, "dentry: %p\n", dentry);
1029 v9ses = v9fs_dentry2v9ses(dentry);
1030 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
1031 generic_fillattr(&init_user_ns, d_inode(dentry), stat);
1032 return 0;
1033 }
1034 fid = v9fs_fid_lookup(dentry);
1035 if (IS_ERR(fid))
1036 return PTR_ERR(fid);
1037
1038 st = p9_client_stat(fid);
1039 p9_client_clunk(fid);
1040 if (IS_ERR(st))
1041 return PTR_ERR(st);
1042
1043 v9fs_stat2inode(st, d_inode(dentry), dentry->d_sb, 0);
1044 generic_fillattr(&init_user_ns, d_inode(dentry), stat);
1045
1046 p9stat_free(st);
1047 kfree(st);
1048 return 0;
1049}
1050
1051/**
1052 * v9fs_vfs_setattr - set file metadata
1053 * @dentry: file whose metadata to set
1054 * @iattr: metadata assignment structure
1055 *
1056 */
1057
1058static int v9fs_vfs_setattr(struct user_namespace *mnt_userns,
1059 struct dentry *dentry, struct iattr *iattr)
1060{
1061 int retval, use_dentry = 0;
1062 struct v9fs_session_info *v9ses;
1063 struct p9_fid *fid = NULL;
1064 struct p9_wstat wstat;
1065
1066 p9_debug(P9_DEBUG_VFS, "\n");
1067 retval = setattr_prepare(&init_user_ns, dentry, iattr);
1068 if (retval)
1069 return retval;
1070
1071 retval = -EPERM;
1072 v9ses = v9fs_dentry2v9ses(dentry);
1073 if (iattr->ia_valid & ATTR_FILE) {
1074 fid = iattr->ia_file->private_data;
1075 WARN_ON(!fid);
1076 }
1077 if (!fid) {
1078 fid = v9fs_fid_lookup(dentry);
1079 use_dentry = 1;
1080 }
1081 if(IS_ERR(fid))
1082 return PTR_ERR(fid);
1083
1084 v9fs_blank_wstat(&wstat);
1085 if (iattr->ia_valid & ATTR_MODE)
1086 wstat.mode = unixmode2p9mode(v9ses, iattr->ia_mode);
1087
1088 if (iattr->ia_valid & ATTR_MTIME)
1089 wstat.mtime = iattr->ia_mtime.tv_sec;
1090
1091 if (iattr->ia_valid & ATTR_ATIME)
1092 wstat.atime = iattr->ia_atime.tv_sec;
1093
1094 if (iattr->ia_valid & ATTR_SIZE)
1095 wstat.length = iattr->ia_size;
1096
1097 if (v9fs_proto_dotu(v9ses)) {
1098 if (iattr->ia_valid & ATTR_UID)
1099 wstat.n_uid = iattr->ia_uid;
1100
1101 if (iattr->ia_valid & ATTR_GID)
1102 wstat.n_gid = iattr->ia_gid;
1103 }
1104
1105 /* Write all dirty data */
1106 if (d_is_reg(dentry))
1107 filemap_write_and_wait(d_inode(dentry)->i_mapping);
1108
1109 retval = p9_client_wstat(fid, &wstat);
1110
1111 if (use_dentry)
1112 p9_client_clunk(fid);
1113
1114 if (retval < 0)
1115 return retval;
1116
1117 if ((iattr->ia_valid & ATTR_SIZE) &&
1118 iattr->ia_size != i_size_read(d_inode(dentry)))
1119 truncate_setsize(d_inode(dentry), iattr->ia_size);
1120
1121 v9fs_invalidate_inode_attr(d_inode(dentry));
1122
1123 setattr_copy(&init_user_ns, d_inode(dentry), iattr);
1124 mark_inode_dirty(d_inode(dentry));
1125 return 0;
1126}
1127
1128/**
1129 * v9fs_stat2inode - populate an inode structure with mistat info
1130 * @stat: Plan 9 metadata (mistat) structure
1131 * @inode: inode to populate
1132 * @sb: superblock of filesystem
1133 * @flags: control flags (e.g. V9FS_STAT2INODE_KEEP_ISIZE)
1134 *
1135 */
1136
1137void
1138v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
1139 struct super_block *sb, unsigned int flags)
1140{
1141 umode_t mode;
1142 struct v9fs_session_info *v9ses = sb->s_fs_info;
1143 struct v9fs_inode *v9inode = V9FS_I(inode);
1144
1145 set_nlink(inode, 1);
1146
1147 inode->i_atime.tv_sec = stat->atime;
1148 inode->i_mtime.tv_sec = stat->mtime;
1149 inode->i_ctime.tv_sec = stat->mtime;
1150
1151 inode->i_uid = v9ses->dfltuid;
1152 inode->i_gid = v9ses->dfltgid;
1153
1154 if (v9fs_proto_dotu(v9ses)) {
1155 inode->i_uid = stat->n_uid;
1156 inode->i_gid = stat->n_gid;
1157 }
1158 if ((S_ISREG(inode->i_mode)) || (S_ISDIR(inode->i_mode))) {
1159 if (v9fs_proto_dotu(v9ses)) {
1160 unsigned int i_nlink;
1161 /*
1162 * Hadlink support got added later to the .u extension.
1163 * So there can be a server out there that doesn't
1164 * support this even with .u extension. That would
1165 * just leave us with stat->extension being an empty
1166 * string, though.
1167 */
1168 /* HARDLINKCOUNT %u */
1169 if (sscanf(stat->extension,
1170 " HARDLINKCOUNT %u", &i_nlink) == 1)
1171 set_nlink(inode, i_nlink);
1172 }
1173 }
1174 mode = p9mode2perm(v9ses, stat);
1175 mode |= inode->i_mode & ~S_IALLUGO;
1176 inode->i_mode = mode;
1177
1178 if (!(flags & V9FS_STAT2INODE_KEEP_ISIZE))
1179 v9fs_i_size_write(inode, stat->length);
1180 /* not real number of blocks, but 512 byte ones ... */
1181 inode->i_blocks = (stat->length + 512 - 1) >> 9;
1182 v9inode->cache_validity &= ~V9FS_INO_INVALID_ATTR;
1183}
1184
1185/**
1186 * v9fs_qid2ino - convert qid into inode number
1187 * @qid: qid to hash
1188 *
1189 * BUG: potential for inode number collisions?
1190 */
1191
1192ino_t v9fs_qid2ino(struct p9_qid *qid)
1193{
1194 u64 path = qid->path + 2;
1195 ino_t i = 0;
1196
1197 if (sizeof(ino_t) == sizeof(path))
1198 memcpy(&i, &path, sizeof(ino_t));
1199 else
1200 i = (ino_t) (path ^ (path >> 32));
1201
1202 return i;
1203}
1204
1205/**
1206 * v9fs_vfs_get_link - follow a symlink path
1207 * @dentry: dentry for symlink
1208 * @inode: inode for symlink
1209 * @done: delayed call for when we are done with the return value
1210 */
1211
1212static const char *v9fs_vfs_get_link(struct dentry *dentry,
1213 struct inode *inode,
1214 struct delayed_call *done)
1215{
1216 struct v9fs_session_info *v9ses;
1217 struct p9_fid *fid;
1218 struct p9_wstat *st;
1219 char *res;
1220
1221 if (!dentry)
1222 return ERR_PTR(-ECHILD);
1223
1224 v9ses = v9fs_dentry2v9ses(dentry);
1225 fid = v9fs_fid_lookup(dentry);
1226 p9_debug(P9_DEBUG_VFS, "%pd\n", dentry);
1227
1228 if (IS_ERR(fid))
1229 return ERR_CAST(fid);
1230
1231 if (!v9fs_proto_dotu(v9ses))
1232 return ERR_PTR(-EBADF);
1233
1234 st = p9_client_stat(fid);
1235 p9_client_clunk(fid);
1236 if (IS_ERR(st))
1237 return ERR_CAST(st);
1238
1239 if (!(st->mode & P9_DMSYMLINK)) {
1240 p9stat_free(st);
1241 kfree(st);
1242 return ERR_PTR(-EINVAL);
1243 }
1244 res = st->extension;
1245 st->extension = NULL;
1246 if (strlen(res) >= PATH_MAX)
1247 res[PATH_MAX - 1] = '\0';
1248
1249 p9stat_free(st);
1250 kfree(st);
1251 set_delayed_call(done, kfree_link, res);
1252 return res;
1253}
1254
1255/**
1256 * v9fs_vfs_mkspecial - create a special file
1257 * @dir: inode to create special file in
1258 * @dentry: dentry to create
1259 * @perm: mode to create special file
1260 * @extension: 9p2000.u format extension string representing special file
1261 *
1262 */
1263
1264static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
1265 u32 perm, const char *extension)
1266{
1267 struct p9_fid *fid;
1268 struct v9fs_session_info *v9ses;
1269
1270 v9ses = v9fs_inode2v9ses(dir);
1271 if (!v9fs_proto_dotu(v9ses)) {
1272 p9_debug(P9_DEBUG_ERROR, "not extended\n");
1273 return -EPERM;
1274 }
1275
1276 fid = v9fs_create(v9ses, dir, dentry, (char *) extension, perm,
1277 P9_OREAD);
1278 if (IS_ERR(fid))
1279 return PTR_ERR(fid);
1280
1281 v9fs_invalidate_inode_attr(dir);
1282 p9_client_clunk(fid);
1283 return 0;
1284}
1285
1286/**
1287 * v9fs_vfs_symlink - helper function to create symlinks
1288 * @dir: directory inode containing symlink
1289 * @dentry: dentry for symlink
1290 * @symname: symlink data
1291 *
1292 * See Also: 9P2000.u RFC for more information
1293 *
1294 */
1295
1296static int
1297v9fs_vfs_symlink(struct user_namespace *mnt_userns, struct inode *dir,
1298 struct dentry *dentry, const char *symname)
1299{
1300 p9_debug(P9_DEBUG_VFS, " %lu,%pd,%s\n",
1301 dir->i_ino, dentry, symname);
1302
1303 return v9fs_vfs_mkspecial(dir, dentry, P9_DMSYMLINK, symname);
1304}
1305
1306#define U32_MAX_DIGITS 10
1307
1308/**
1309 * v9fs_vfs_link - create a hardlink
1310 * @old_dentry: dentry for file to link to
1311 * @dir: inode destination for new link
1312 * @dentry: dentry for link
1313 *
1314 */
1315
1316static int
1317v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
1318 struct dentry *dentry)
1319{
1320 int retval;
1321 char name[1 + U32_MAX_DIGITS + 2]; /* sign + number + \n + \0 */
1322 struct p9_fid *oldfid;
1323
1324 p9_debug(P9_DEBUG_VFS, " %lu,%pd,%pd\n",
1325 dir->i_ino, dentry, old_dentry);
1326
1327 oldfid = v9fs_fid_clone(old_dentry);
1328 if (IS_ERR(oldfid))
1329 return PTR_ERR(oldfid);
1330
1331 sprintf(name, "%d\n", oldfid->fid);
1332 retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name);
1333 if (!retval) {
1334 v9fs_refresh_inode(oldfid, d_inode(old_dentry));
1335 v9fs_invalidate_inode_attr(dir);
1336 }
1337 p9_client_clunk(oldfid);
1338 return retval;
1339}
1340
1341/**
1342 * v9fs_vfs_mknod - create a special file
1343 * @dir: inode destination for new link
1344 * @dentry: dentry for file
1345 * @mode: mode for creation
1346 * @rdev: device associated with special file
1347 *
1348 */
1349
1350static int
1351v9fs_vfs_mknod(struct user_namespace *mnt_userns, struct inode *dir,
1352 struct dentry *dentry, umode_t mode, dev_t rdev)
1353{
1354 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
1355 int retval;
1356 char name[2 + U32_MAX_DIGITS + 1 + U32_MAX_DIGITS + 1];
1357 u32 perm;
1358
1359 p9_debug(P9_DEBUG_VFS, " %lu,%pd mode: %hx MAJOR: %u MINOR: %u\n",
1360 dir->i_ino, dentry, mode,
1361 MAJOR(rdev), MINOR(rdev));
1362
1363 /* build extension */
1364 if (S_ISBLK(mode))
1365 sprintf(name, "b %u %u", MAJOR(rdev), MINOR(rdev));
1366 else if (S_ISCHR(mode))
1367 sprintf(name, "c %u %u", MAJOR(rdev), MINOR(rdev));
1368 else
1369 *name = 0;
1370
1371 perm = unixmode2p9mode(v9ses, mode);
1372 retval = v9fs_vfs_mkspecial(dir, dentry, perm, name);
1373
1374 return retval;
1375}
1376
1377int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode)
1378{
1379 int umode;
1380 dev_t rdev;
1381 struct p9_wstat *st;
1382 struct v9fs_session_info *v9ses;
1383 unsigned int flags;
1384
1385 v9ses = v9fs_inode2v9ses(inode);
1386 st = p9_client_stat(fid);
1387 if (IS_ERR(st))
1388 return PTR_ERR(st);
1389 /*
1390 * Don't update inode if the file type is different
1391 */
1392 umode = p9mode2unixmode(v9ses, st, &rdev);
1393 if (inode_wrong_type(inode, umode))
1394 goto out;
1395
1396 /*
1397 * We don't want to refresh inode->i_size,
1398 * because we may have cached data
1399 */
1400 flags = (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) ?
1401 V9FS_STAT2INODE_KEEP_ISIZE : 0;
1402 v9fs_stat2inode(st, inode, inode->i_sb, flags);
1403out:
1404 p9stat_free(st);
1405 kfree(st);
1406 return 0;
1407}
1408
1409static const struct inode_operations v9fs_dir_inode_operations_dotu = {
1410 .create = v9fs_vfs_create,
1411 .lookup = v9fs_vfs_lookup,
1412 .atomic_open = v9fs_vfs_atomic_open,
1413 .symlink = v9fs_vfs_symlink,
1414 .link = v9fs_vfs_link,
1415 .unlink = v9fs_vfs_unlink,
1416 .mkdir = v9fs_vfs_mkdir,
1417 .rmdir = v9fs_vfs_rmdir,
1418 .mknod = v9fs_vfs_mknod,
1419 .rename = v9fs_vfs_rename,
1420 .getattr = v9fs_vfs_getattr,
1421 .setattr = v9fs_vfs_setattr,
1422};
1423
1424static const struct inode_operations v9fs_dir_inode_operations = {
1425 .create = v9fs_vfs_create,
1426 .lookup = v9fs_vfs_lookup,
1427 .atomic_open = v9fs_vfs_atomic_open,
1428 .unlink = v9fs_vfs_unlink,
1429 .mkdir = v9fs_vfs_mkdir,
1430 .rmdir = v9fs_vfs_rmdir,
1431 .mknod = v9fs_vfs_mknod,
1432 .rename = v9fs_vfs_rename,
1433 .getattr = v9fs_vfs_getattr,
1434 .setattr = v9fs_vfs_setattr,
1435};
1436
1437static const struct inode_operations v9fs_file_inode_operations = {
1438 .getattr = v9fs_vfs_getattr,
1439 .setattr = v9fs_vfs_setattr,
1440};
1441
1442static const struct inode_operations v9fs_symlink_inode_operations = {
1443 .get_link = v9fs_vfs_get_link,
1444 .getattr = v9fs_vfs_getattr,
1445 .setattr = v9fs_vfs_setattr,
1446};
1447
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * linux/fs/9p/vfs_inode.c
4 *
5 * This file contains vfs inode ops for the 9P2000 protocol.
6 *
7 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
8 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
9 */
10
11#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12
13#include <linux/module.h>
14#include <linux/errno.h>
15#include <linux/fs.h>
16#include <linux/file.h>
17#include <linux/pagemap.h>
18#include <linux/stat.h>
19#include <linux/string.h>
20#include <linux/inet.h>
21#include <linux/namei.h>
22#include <linux/idr.h>
23#include <linux/sched.h>
24#include <linux/slab.h>
25#include <linux/xattr.h>
26#include <linux/posix_acl.h>
27#include <net/9p/9p.h>
28#include <net/9p/client.h>
29
30#include "v9fs.h"
31#include "v9fs_vfs.h"
32#include "fid.h"
33#include "cache.h"
34#include "xattr.h"
35#include "acl.h"
36
37static const struct inode_operations v9fs_dir_inode_operations;
38static const struct inode_operations v9fs_dir_inode_operations_dotu;
39static const struct inode_operations v9fs_file_inode_operations;
40static const struct inode_operations v9fs_symlink_inode_operations;
41
42/**
43 * unixmode2p9mode - convert unix mode bits to plan 9
44 * @v9ses: v9fs session information
45 * @mode: mode to convert
46 *
47 */
48
49static u32 unixmode2p9mode(struct v9fs_session_info *v9ses, umode_t mode)
50{
51 int res;
52 res = mode & 0777;
53 if (S_ISDIR(mode))
54 res |= P9_DMDIR;
55 if (v9fs_proto_dotu(v9ses)) {
56 if (v9ses->nodev == 0) {
57 if (S_ISSOCK(mode))
58 res |= P9_DMSOCKET;
59 if (S_ISFIFO(mode))
60 res |= P9_DMNAMEDPIPE;
61 if (S_ISBLK(mode))
62 res |= P9_DMDEVICE;
63 if (S_ISCHR(mode))
64 res |= P9_DMDEVICE;
65 }
66
67 if ((mode & S_ISUID) == S_ISUID)
68 res |= P9_DMSETUID;
69 if ((mode & S_ISGID) == S_ISGID)
70 res |= P9_DMSETGID;
71 if ((mode & S_ISVTX) == S_ISVTX)
72 res |= P9_DMSETVTX;
73 }
74 return res;
75}
76
77/**
78 * p9mode2perm- convert plan9 mode bits to unix permission bits
79 * @v9ses: v9fs session information
80 * @stat: p9_wstat from which mode need to be derived
81 *
82 */
83static int p9mode2perm(struct v9fs_session_info *v9ses,
84 struct p9_wstat *stat)
85{
86 int res;
87 int mode = stat->mode;
88
89 res = mode & S_IALLUGO;
90 if (v9fs_proto_dotu(v9ses)) {
91 if ((mode & P9_DMSETUID) == P9_DMSETUID)
92 res |= S_ISUID;
93
94 if ((mode & P9_DMSETGID) == P9_DMSETGID)
95 res |= S_ISGID;
96
97 if ((mode & P9_DMSETVTX) == P9_DMSETVTX)
98 res |= S_ISVTX;
99 }
100 return res;
101}
102
103/**
104 * p9mode2unixmode- convert plan9 mode bits to unix mode bits
105 * @v9ses: v9fs session information
106 * @stat: p9_wstat from which mode need to be derived
107 * @rdev: major number, minor number in case of device files.
108 *
109 */
110static umode_t p9mode2unixmode(struct v9fs_session_info *v9ses,
111 struct p9_wstat *stat, dev_t *rdev)
112{
113 int res;
114 u32 mode = stat->mode;
115
116 *rdev = 0;
117 res = p9mode2perm(v9ses, stat);
118
119 if ((mode & P9_DMDIR) == P9_DMDIR)
120 res |= S_IFDIR;
121 else if ((mode & P9_DMSYMLINK) && (v9fs_proto_dotu(v9ses)))
122 res |= S_IFLNK;
123 else if ((mode & P9_DMSOCKET) && (v9fs_proto_dotu(v9ses))
124 && (v9ses->nodev == 0))
125 res |= S_IFSOCK;
126 else if ((mode & P9_DMNAMEDPIPE) && (v9fs_proto_dotu(v9ses))
127 && (v9ses->nodev == 0))
128 res |= S_IFIFO;
129 else if ((mode & P9_DMDEVICE) && (v9fs_proto_dotu(v9ses))
130 && (v9ses->nodev == 0)) {
131 char type = 0, ext[32];
132 int major = -1, minor = -1;
133
134 strlcpy(ext, stat->extension, sizeof(ext));
135 sscanf(ext, "%c %i %i", &type, &major, &minor);
136 switch (type) {
137 case 'c':
138 res |= S_IFCHR;
139 break;
140 case 'b':
141 res |= S_IFBLK;
142 break;
143 default:
144 p9_debug(P9_DEBUG_ERROR, "Unknown special type %c %s\n",
145 type, stat->extension);
146 }
147 *rdev = MKDEV(major, minor);
148 } else
149 res |= S_IFREG;
150
151 return res;
152}
153
154/**
155 * v9fs_uflags2omode- convert posix open flags to plan 9 mode bits
156 * @uflags: flags to convert
157 * @extended: if .u extensions are active
158 */
159
160int v9fs_uflags2omode(int uflags, int extended)
161{
162 int ret;
163
164 ret = 0;
165 switch (uflags&3) {
166 default:
167 case O_RDONLY:
168 ret = P9_OREAD;
169 break;
170
171 case O_WRONLY:
172 ret = P9_OWRITE;
173 break;
174
175 case O_RDWR:
176 ret = P9_ORDWR;
177 break;
178 }
179
180 if (extended) {
181 if (uflags & O_EXCL)
182 ret |= P9_OEXCL;
183
184 if (uflags & O_APPEND)
185 ret |= P9_OAPPEND;
186 }
187
188 return ret;
189}
190
191/**
192 * v9fs_blank_wstat - helper function to setup a 9P stat structure
193 * @wstat: structure to initialize
194 *
195 */
196
197void
198v9fs_blank_wstat(struct p9_wstat *wstat)
199{
200 wstat->type = ~0;
201 wstat->dev = ~0;
202 wstat->qid.type = ~0;
203 wstat->qid.version = ~0;
204 *((long long *)&wstat->qid.path) = ~0;
205 wstat->mode = ~0;
206 wstat->atime = ~0;
207 wstat->mtime = ~0;
208 wstat->length = ~0;
209 wstat->name = NULL;
210 wstat->uid = NULL;
211 wstat->gid = NULL;
212 wstat->muid = NULL;
213 wstat->n_uid = INVALID_UID;
214 wstat->n_gid = INVALID_GID;
215 wstat->n_muid = INVALID_UID;
216 wstat->extension = NULL;
217}
218
219/**
220 * v9fs_alloc_inode - helper function to allocate an inode
221 *
222 */
223struct inode *v9fs_alloc_inode(struct super_block *sb)
224{
225 struct v9fs_inode *v9inode;
226 v9inode = kmem_cache_alloc(v9fs_inode_cache, GFP_KERNEL);
227 if (!v9inode)
228 return NULL;
229#ifdef CONFIG_9P_FSCACHE
230 v9inode->fscache = NULL;
231 mutex_init(&v9inode->fscache_lock);
232#endif
233 v9inode->writeback_fid = NULL;
234 v9inode->cache_validity = 0;
235 mutex_init(&v9inode->v_mutex);
236 return &v9inode->vfs_inode;
237}
238
239/**
240 * v9fs_free_inode - destroy an inode
241 *
242 */
243
244void v9fs_free_inode(struct inode *inode)
245{
246 kmem_cache_free(v9fs_inode_cache, V9FS_I(inode));
247}
248
249int v9fs_init_inode(struct v9fs_session_info *v9ses,
250 struct inode *inode, umode_t mode, dev_t rdev)
251{
252 int err = 0;
253
254 inode_init_owner(inode, NULL, mode);
255 inode->i_blocks = 0;
256 inode->i_rdev = rdev;
257 inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
258 inode->i_mapping->a_ops = &v9fs_addr_operations;
259
260 switch (mode & S_IFMT) {
261 case S_IFIFO:
262 case S_IFBLK:
263 case S_IFCHR:
264 case S_IFSOCK:
265 if (v9fs_proto_dotl(v9ses)) {
266 inode->i_op = &v9fs_file_inode_operations_dotl;
267 } else if (v9fs_proto_dotu(v9ses)) {
268 inode->i_op = &v9fs_file_inode_operations;
269 } else {
270 p9_debug(P9_DEBUG_ERROR,
271 "special files without extended mode\n");
272 err = -EINVAL;
273 goto error;
274 }
275 init_special_inode(inode, inode->i_mode, inode->i_rdev);
276 break;
277 case S_IFREG:
278 if (v9fs_proto_dotl(v9ses)) {
279 inode->i_op = &v9fs_file_inode_operations_dotl;
280 if (v9ses->cache == CACHE_LOOSE ||
281 v9ses->cache == CACHE_FSCACHE)
282 inode->i_fop =
283 &v9fs_cached_file_operations_dotl;
284 else if (v9ses->cache == CACHE_MMAP)
285 inode->i_fop = &v9fs_mmap_file_operations_dotl;
286 else
287 inode->i_fop = &v9fs_file_operations_dotl;
288 } else {
289 inode->i_op = &v9fs_file_inode_operations;
290 if (v9ses->cache == CACHE_LOOSE ||
291 v9ses->cache == CACHE_FSCACHE)
292 inode->i_fop =
293 &v9fs_cached_file_operations;
294 else if (v9ses->cache == CACHE_MMAP)
295 inode->i_fop = &v9fs_mmap_file_operations;
296 else
297 inode->i_fop = &v9fs_file_operations;
298 }
299
300 break;
301 case S_IFLNK:
302 if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)) {
303 p9_debug(P9_DEBUG_ERROR,
304 "extended modes used with legacy protocol\n");
305 err = -EINVAL;
306 goto error;
307 }
308
309 if (v9fs_proto_dotl(v9ses))
310 inode->i_op = &v9fs_symlink_inode_operations_dotl;
311 else
312 inode->i_op = &v9fs_symlink_inode_operations;
313
314 break;
315 case S_IFDIR:
316 inc_nlink(inode);
317 if (v9fs_proto_dotl(v9ses))
318 inode->i_op = &v9fs_dir_inode_operations_dotl;
319 else if (v9fs_proto_dotu(v9ses))
320 inode->i_op = &v9fs_dir_inode_operations_dotu;
321 else
322 inode->i_op = &v9fs_dir_inode_operations;
323
324 if (v9fs_proto_dotl(v9ses))
325 inode->i_fop = &v9fs_dir_operations_dotl;
326 else
327 inode->i_fop = &v9fs_dir_operations;
328
329 break;
330 default:
331 p9_debug(P9_DEBUG_ERROR, "BAD mode 0x%hx S_IFMT 0x%x\n",
332 mode, mode & S_IFMT);
333 err = -EINVAL;
334 goto error;
335 }
336error:
337 return err;
338
339}
340
341/**
342 * v9fs_get_inode - helper function to setup an inode
343 * @sb: superblock
344 * @mode: mode to setup inode with
345 *
346 */
347
348struct inode *v9fs_get_inode(struct super_block *sb, umode_t mode, dev_t rdev)
349{
350 int err;
351 struct inode *inode;
352 struct v9fs_session_info *v9ses = sb->s_fs_info;
353
354 p9_debug(P9_DEBUG_VFS, "super block: %p mode: %ho\n", sb, mode);
355
356 inode = new_inode(sb);
357 if (!inode) {
358 pr_warn("%s (%d): Problem allocating inode\n",
359 __func__, task_pid_nr(current));
360 return ERR_PTR(-ENOMEM);
361 }
362 err = v9fs_init_inode(v9ses, inode, mode, rdev);
363 if (err) {
364 iput(inode);
365 return ERR_PTR(err);
366 }
367 return inode;
368}
369
370/**
371 * v9fs_clear_inode - release an inode
372 * @inode: inode to release
373 *
374 */
375void v9fs_evict_inode(struct inode *inode)
376{
377 struct v9fs_inode *v9inode = V9FS_I(inode);
378
379 truncate_inode_pages_final(&inode->i_data);
380 clear_inode(inode);
381 filemap_fdatawrite(&inode->i_data);
382
383 v9fs_cache_inode_put_cookie(inode);
384 /* clunk the fid stashed in writeback_fid */
385 if (v9inode->writeback_fid) {
386 p9_client_clunk(v9inode->writeback_fid);
387 v9inode->writeback_fid = NULL;
388 }
389}
390
391static int v9fs_test_inode(struct inode *inode, void *data)
392{
393 int umode;
394 dev_t rdev;
395 struct v9fs_inode *v9inode = V9FS_I(inode);
396 struct p9_wstat *st = (struct p9_wstat *)data;
397 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
398
399 umode = p9mode2unixmode(v9ses, st, &rdev);
400 /* don't match inode of different type */
401 if ((inode->i_mode & S_IFMT) != (umode & S_IFMT))
402 return 0;
403
404 /* compare qid details */
405 if (memcmp(&v9inode->qid.version,
406 &st->qid.version, sizeof(v9inode->qid.version)))
407 return 0;
408
409 if (v9inode->qid.type != st->qid.type)
410 return 0;
411
412 if (v9inode->qid.path != st->qid.path)
413 return 0;
414 return 1;
415}
416
417static int v9fs_test_new_inode(struct inode *inode, void *data)
418{
419 return 0;
420}
421
422static int v9fs_set_inode(struct inode *inode, void *data)
423{
424 struct v9fs_inode *v9inode = V9FS_I(inode);
425 struct p9_wstat *st = (struct p9_wstat *)data;
426
427 memcpy(&v9inode->qid, &st->qid, sizeof(st->qid));
428 return 0;
429}
430
431static struct inode *v9fs_qid_iget(struct super_block *sb,
432 struct p9_qid *qid,
433 struct p9_wstat *st,
434 int new)
435{
436 dev_t rdev;
437 int retval;
438 umode_t umode;
439 unsigned long i_ino;
440 struct inode *inode;
441 struct v9fs_session_info *v9ses = sb->s_fs_info;
442 int (*test)(struct inode *, void *);
443
444 if (new)
445 test = v9fs_test_new_inode;
446 else
447 test = v9fs_test_inode;
448
449 i_ino = v9fs_qid2ino(qid);
450 inode = iget5_locked(sb, i_ino, test, v9fs_set_inode, st);
451 if (!inode)
452 return ERR_PTR(-ENOMEM);
453 if (!(inode->i_state & I_NEW))
454 return inode;
455 /*
456 * initialize the inode with the stat info
457 * FIXME!! we may need support for stale inodes
458 * later.
459 */
460 inode->i_ino = i_ino;
461 umode = p9mode2unixmode(v9ses, st, &rdev);
462 retval = v9fs_init_inode(v9ses, inode, umode, rdev);
463 if (retval)
464 goto error;
465
466 v9fs_stat2inode(st, inode, sb, 0);
467 v9fs_cache_inode_get_cookie(inode);
468 unlock_new_inode(inode);
469 return inode;
470error:
471 iget_failed(inode);
472 return ERR_PTR(retval);
473
474}
475
476struct inode *
477v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
478 struct super_block *sb, int new)
479{
480 struct p9_wstat *st;
481 struct inode *inode = NULL;
482
483 st = p9_client_stat(fid);
484 if (IS_ERR(st))
485 return ERR_CAST(st);
486
487 inode = v9fs_qid_iget(sb, &st->qid, st, new);
488 p9stat_free(st);
489 kfree(st);
490 return inode;
491}
492
493/**
494 * v9fs_at_to_dotl_flags- convert Linux specific AT flags to
495 * plan 9 AT flag.
496 * @flags: flags to convert
497 */
498static int v9fs_at_to_dotl_flags(int flags)
499{
500 int rflags = 0;
501 if (flags & AT_REMOVEDIR)
502 rflags |= P9_DOTL_AT_REMOVEDIR;
503 return rflags;
504}
505
506/**
507 * v9fs_dec_count - helper functon to drop i_nlink.
508 *
509 * If a directory had nlink <= 2 (including . and ..), then we should not drop
510 * the link count, which indicates the underlying exported fs doesn't maintain
511 * nlink accurately. e.g.
512 * - overlayfs sets nlink to 1 for merged dir
513 * - ext4 (with dir_nlink feature enabled) sets nlink to 1 if a dir has more
514 * than EXT4_LINK_MAX (65000) links.
515 *
516 * @inode: inode whose nlink is being dropped
517 */
518static void v9fs_dec_count(struct inode *inode)
519{
520 if (!S_ISDIR(inode->i_mode) || inode->i_nlink > 2)
521 drop_nlink(inode);
522}
523
524/**
525 * v9fs_remove - helper function to remove files and directories
526 * @dir: directory inode that is being deleted
527 * @dentry: dentry that is being deleted
528 * @flags: removing a directory
529 *
530 */
531
532static int v9fs_remove(struct inode *dir, struct dentry *dentry, int flags)
533{
534 struct inode *inode;
535 int retval = -EOPNOTSUPP;
536 struct p9_fid *v9fid, *dfid;
537 struct v9fs_session_info *v9ses;
538
539 p9_debug(P9_DEBUG_VFS, "inode: %p dentry: %p rmdir: %x\n",
540 dir, dentry, flags);
541
542 v9ses = v9fs_inode2v9ses(dir);
543 inode = d_inode(dentry);
544 dfid = v9fs_parent_fid(dentry);
545 if (IS_ERR(dfid)) {
546 retval = PTR_ERR(dfid);
547 p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", retval);
548 return retval;
549 }
550 if (v9fs_proto_dotl(v9ses))
551 retval = p9_client_unlinkat(dfid, dentry->d_name.name,
552 v9fs_at_to_dotl_flags(flags));
553 if (retval == -EOPNOTSUPP) {
554 /* Try the one based on path */
555 v9fid = v9fs_fid_clone(dentry);
556 if (IS_ERR(v9fid))
557 return PTR_ERR(v9fid);
558 retval = p9_client_remove(v9fid);
559 }
560 if (!retval) {
561 /*
562 * directories on unlink should have zero
563 * link count
564 */
565 if (flags & AT_REMOVEDIR) {
566 clear_nlink(inode);
567 v9fs_dec_count(dir);
568 } else
569 v9fs_dec_count(inode);
570
571 v9fs_invalidate_inode_attr(inode);
572 v9fs_invalidate_inode_attr(dir);
573 }
574 return retval;
575}
576
577/**
578 * v9fs_create - Create a file
579 * @v9ses: session information
580 * @dir: directory that dentry is being created in
581 * @dentry: dentry that is being created
582 * @extension: 9p2000.u extension string to support devices, etc.
583 * @perm: create permissions
584 * @mode: open mode
585 *
586 */
587static struct p9_fid *
588v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
589 struct dentry *dentry, char *extension, u32 perm, u8 mode)
590{
591 int err;
592 const unsigned char *name;
593 struct p9_fid *dfid, *ofid, *fid;
594 struct inode *inode;
595
596 p9_debug(P9_DEBUG_VFS, "name %pd\n", dentry);
597
598 err = 0;
599 ofid = NULL;
600 fid = NULL;
601 name = dentry->d_name.name;
602 dfid = v9fs_parent_fid(dentry);
603 if (IS_ERR(dfid)) {
604 err = PTR_ERR(dfid);
605 p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
606 return ERR_PTR(err);
607 }
608
609 /* clone a fid to use for creation */
610 ofid = clone_fid(dfid);
611 if (IS_ERR(ofid)) {
612 err = PTR_ERR(ofid);
613 p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
614 return ERR_PTR(err);
615 }
616
617 err = p9_client_fcreate(ofid, name, perm, mode, extension);
618 if (err < 0) {
619 p9_debug(P9_DEBUG_VFS, "p9_client_fcreate failed %d\n", err);
620 goto error;
621 }
622
623 if (!(perm & P9_DMLINK)) {
624 /* now walk from the parent so we can get unopened fid */
625 fid = p9_client_walk(dfid, 1, &name, 1);
626 if (IS_ERR(fid)) {
627 err = PTR_ERR(fid);
628 p9_debug(P9_DEBUG_VFS,
629 "p9_client_walk failed %d\n", err);
630 fid = NULL;
631 goto error;
632 }
633 /*
634 * instantiate inode and assign the unopened fid to the dentry
635 */
636 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
637 if (IS_ERR(inode)) {
638 err = PTR_ERR(inode);
639 p9_debug(P9_DEBUG_VFS,
640 "inode creation failed %d\n", err);
641 goto error;
642 }
643 v9fs_fid_add(dentry, fid);
644 d_instantiate(dentry, inode);
645 }
646 return ofid;
647error:
648 if (ofid)
649 p9_client_clunk(ofid);
650
651 if (fid)
652 p9_client_clunk(fid);
653
654 return ERR_PTR(err);
655}
656
657/**
658 * v9fs_vfs_create - VFS hook to create a regular file
659 *
660 * open(.., O_CREAT) is handled in v9fs_vfs_atomic_open(). This is only called
661 * for mknod(2).
662 *
663 * @dir: directory inode that is being created
664 * @dentry: dentry that is being deleted
665 * @mode: create permissions
666 *
667 */
668
669static int
670v9fs_vfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
671 bool excl)
672{
673 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
674 u32 perm = unixmode2p9mode(v9ses, mode);
675 struct p9_fid *fid;
676
677 /* P9_OEXCL? */
678 fid = v9fs_create(v9ses, dir, dentry, NULL, perm, P9_ORDWR);
679 if (IS_ERR(fid))
680 return PTR_ERR(fid);
681
682 v9fs_invalidate_inode_attr(dir);
683 p9_client_clunk(fid);
684
685 return 0;
686}
687
688/**
689 * v9fs_vfs_mkdir - VFS mkdir hook to create a directory
690 * @dir: inode that is being unlinked
691 * @dentry: dentry that is being unlinked
692 * @mode: mode for new directory
693 *
694 */
695
696static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
697{
698 int err;
699 u32 perm;
700 struct p9_fid *fid;
701 struct v9fs_session_info *v9ses;
702
703 p9_debug(P9_DEBUG_VFS, "name %pd\n", dentry);
704 err = 0;
705 v9ses = v9fs_inode2v9ses(dir);
706 perm = unixmode2p9mode(v9ses, mode | S_IFDIR);
707 fid = v9fs_create(v9ses, dir, dentry, NULL, perm, P9_OREAD);
708 if (IS_ERR(fid)) {
709 err = PTR_ERR(fid);
710 fid = NULL;
711 } else {
712 inc_nlink(dir);
713 v9fs_invalidate_inode_attr(dir);
714 }
715
716 if (fid)
717 p9_client_clunk(fid);
718
719 return err;
720}
721
722/**
723 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
724 * @dir: inode that is being walked from
725 * @dentry: dentry that is being walked to?
726 * @flags: lookup flags (unused)
727 *
728 */
729
730struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
731 unsigned int flags)
732{
733 struct dentry *res;
734 struct v9fs_session_info *v9ses;
735 struct p9_fid *dfid, *fid;
736 struct inode *inode;
737 const unsigned char *name;
738
739 p9_debug(P9_DEBUG_VFS, "dir: %p dentry: (%pd) %p flags: %x\n",
740 dir, dentry, dentry, flags);
741
742 if (dentry->d_name.len > NAME_MAX)
743 return ERR_PTR(-ENAMETOOLONG);
744
745 v9ses = v9fs_inode2v9ses(dir);
746 /* We can walk d_parent because we hold the dir->i_mutex */
747 dfid = v9fs_parent_fid(dentry);
748 if (IS_ERR(dfid))
749 return ERR_CAST(dfid);
750
751 /*
752 * Make sure we don't use a wrong inode due to parallel
753 * unlink. For cached mode create calls request for new
754 * inode. But with cache disabled, lookup should do this.
755 */
756 name = dentry->d_name.name;
757 fid = p9_client_walk(dfid, 1, &name, 1);
758 if (fid == ERR_PTR(-ENOENT))
759 inode = NULL;
760 else if (IS_ERR(fid))
761 inode = ERR_CAST(fid);
762 else if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
763 inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
764 else
765 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
766 /*
767 * If we had a rename on the server and a parallel lookup
768 * for the new name, then make sure we instantiate with
769 * the new name. ie look up for a/b, while on server somebody
770 * moved b under k and client parallely did a lookup for
771 * k/b.
772 */
773 res = d_splice_alias(inode, dentry);
774 if (!IS_ERR(fid)) {
775 if (!res)
776 v9fs_fid_add(dentry, fid);
777 else if (!IS_ERR(res))
778 v9fs_fid_add(res, fid);
779 else
780 p9_client_clunk(fid);
781 }
782 return res;
783}
784
785static int
786v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
787 struct file *file, unsigned flags, umode_t mode)
788{
789 int err;
790 u32 perm;
791 struct v9fs_inode *v9inode;
792 struct v9fs_session_info *v9ses;
793 struct p9_fid *fid, *inode_fid;
794 struct dentry *res = NULL;
795
796 if (d_in_lookup(dentry)) {
797 res = v9fs_vfs_lookup(dir, dentry, 0);
798 if (IS_ERR(res))
799 return PTR_ERR(res);
800
801 if (res)
802 dentry = res;
803 }
804
805 /* Only creates */
806 if (!(flags & O_CREAT) || d_really_is_positive(dentry))
807 return finish_no_open(file, res);
808
809 err = 0;
810
811 v9ses = v9fs_inode2v9ses(dir);
812 perm = unixmode2p9mode(v9ses, mode);
813 fid = v9fs_create(v9ses, dir, dentry, NULL, perm,
814 v9fs_uflags2omode(flags,
815 v9fs_proto_dotu(v9ses)));
816 if (IS_ERR(fid)) {
817 err = PTR_ERR(fid);
818 fid = NULL;
819 goto error;
820 }
821
822 v9fs_invalidate_inode_attr(dir);
823 v9inode = V9FS_I(d_inode(dentry));
824 mutex_lock(&v9inode->v_mutex);
825 if ((v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) &&
826 !v9inode->writeback_fid &&
827 ((flags & O_ACCMODE) != O_RDONLY)) {
828 /*
829 * clone a fid and add it to writeback_fid
830 * we do it during open time instead of
831 * page dirty time via write_begin/page_mkwrite
832 * because we want write after unlink usecase
833 * to work.
834 */
835 inode_fid = v9fs_writeback_fid(dentry);
836 if (IS_ERR(inode_fid)) {
837 err = PTR_ERR(inode_fid);
838 mutex_unlock(&v9inode->v_mutex);
839 goto error;
840 }
841 v9inode->writeback_fid = (void *) inode_fid;
842 }
843 mutex_unlock(&v9inode->v_mutex);
844 err = finish_open(file, dentry, generic_file_open);
845 if (err)
846 goto error;
847
848 file->private_data = fid;
849 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
850 v9fs_cache_inode_set_cookie(d_inode(dentry), file);
851
852 file->f_mode |= FMODE_CREATED;
853out:
854 dput(res);
855 return err;
856
857error:
858 if (fid)
859 p9_client_clunk(fid);
860 goto out;
861}
862
863/**
864 * v9fs_vfs_unlink - VFS unlink hook to delete an inode
865 * @i: inode that is being unlinked
866 * @d: dentry that is being unlinked
867 *
868 */
869
870int v9fs_vfs_unlink(struct inode *i, struct dentry *d)
871{
872 return v9fs_remove(i, d, 0);
873}
874
875/**
876 * v9fs_vfs_rmdir - VFS unlink hook to delete a directory
877 * @i: inode that is being unlinked
878 * @d: dentry that is being unlinked
879 *
880 */
881
882int v9fs_vfs_rmdir(struct inode *i, struct dentry *d)
883{
884 return v9fs_remove(i, d, AT_REMOVEDIR);
885}
886
887/**
888 * v9fs_vfs_rename - VFS hook to rename an inode
889 * @old_dir: old dir inode
890 * @old_dentry: old dentry
891 * @new_dir: new dir inode
892 * @new_dentry: new dentry
893 *
894 */
895
896int
897v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
898 struct inode *new_dir, struct dentry *new_dentry,
899 unsigned int flags)
900{
901 int retval;
902 struct inode *old_inode;
903 struct inode *new_inode;
904 struct v9fs_session_info *v9ses;
905 struct p9_fid *oldfid;
906 struct p9_fid *olddirfid;
907 struct p9_fid *newdirfid;
908 struct p9_wstat wstat;
909
910 if (flags)
911 return -EINVAL;
912
913 p9_debug(P9_DEBUG_VFS, "\n");
914 retval = 0;
915 old_inode = d_inode(old_dentry);
916 new_inode = d_inode(new_dentry);
917 v9ses = v9fs_inode2v9ses(old_inode);
918 oldfid = v9fs_fid_lookup(old_dentry);
919 if (IS_ERR(oldfid))
920 return PTR_ERR(oldfid);
921
922 olddirfid = clone_fid(v9fs_parent_fid(old_dentry));
923 if (IS_ERR(olddirfid)) {
924 retval = PTR_ERR(olddirfid);
925 goto done;
926 }
927
928 newdirfid = clone_fid(v9fs_parent_fid(new_dentry));
929 if (IS_ERR(newdirfid)) {
930 retval = PTR_ERR(newdirfid);
931 goto clunk_olddir;
932 }
933
934 down_write(&v9ses->rename_sem);
935 if (v9fs_proto_dotl(v9ses)) {
936 retval = p9_client_renameat(olddirfid, old_dentry->d_name.name,
937 newdirfid, new_dentry->d_name.name);
938 if (retval == -EOPNOTSUPP)
939 retval = p9_client_rename(oldfid, newdirfid,
940 new_dentry->d_name.name);
941 if (retval != -EOPNOTSUPP)
942 goto clunk_newdir;
943 }
944 if (old_dentry->d_parent != new_dentry->d_parent) {
945 /*
946 * 9P .u can only handle file rename in the same directory
947 */
948
949 p9_debug(P9_DEBUG_ERROR, "old dir and new dir are different\n");
950 retval = -EXDEV;
951 goto clunk_newdir;
952 }
953 v9fs_blank_wstat(&wstat);
954 wstat.muid = v9ses->uname;
955 wstat.name = new_dentry->d_name.name;
956 retval = p9_client_wstat(oldfid, &wstat);
957
958clunk_newdir:
959 if (!retval) {
960 if (new_inode) {
961 if (S_ISDIR(new_inode->i_mode))
962 clear_nlink(new_inode);
963 else
964 v9fs_dec_count(new_inode);
965 }
966 if (S_ISDIR(old_inode->i_mode)) {
967 if (!new_inode)
968 inc_nlink(new_dir);
969 v9fs_dec_count(old_dir);
970 }
971 v9fs_invalidate_inode_attr(old_inode);
972 v9fs_invalidate_inode_attr(old_dir);
973 v9fs_invalidate_inode_attr(new_dir);
974
975 /* successful rename */
976 d_move(old_dentry, new_dentry);
977 }
978 up_write(&v9ses->rename_sem);
979 p9_client_clunk(newdirfid);
980
981clunk_olddir:
982 p9_client_clunk(olddirfid);
983
984done:
985 return retval;
986}
987
988/**
989 * v9fs_vfs_getattr - retrieve file metadata
990 * @path: Object to query
991 * @stat: metadata structure to populate
992 * @request_mask: Mask of STATX_xxx flags indicating the caller's interests
993 * @flags: AT_STATX_xxx setting
994 *
995 */
996
997static int
998v9fs_vfs_getattr(const struct path *path, struct kstat *stat,
999 u32 request_mask, unsigned int flags)
1000{
1001 struct dentry *dentry = path->dentry;
1002 struct v9fs_session_info *v9ses;
1003 struct p9_fid *fid;
1004 struct p9_wstat *st;
1005
1006 p9_debug(P9_DEBUG_VFS, "dentry: %p\n", dentry);
1007 v9ses = v9fs_dentry2v9ses(dentry);
1008 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
1009 generic_fillattr(d_inode(dentry), stat);
1010 return 0;
1011 }
1012 fid = v9fs_fid_lookup(dentry);
1013 if (IS_ERR(fid))
1014 return PTR_ERR(fid);
1015
1016 st = p9_client_stat(fid);
1017 if (IS_ERR(st))
1018 return PTR_ERR(st);
1019
1020 v9fs_stat2inode(st, d_inode(dentry), dentry->d_sb, 0);
1021 generic_fillattr(d_inode(dentry), stat);
1022
1023 p9stat_free(st);
1024 kfree(st);
1025 return 0;
1026}
1027
1028/**
1029 * v9fs_vfs_setattr - set file metadata
1030 * @dentry: file whose metadata to set
1031 * @iattr: metadata assignment structure
1032 *
1033 */
1034
1035static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
1036{
1037 int retval;
1038 struct v9fs_session_info *v9ses;
1039 struct p9_fid *fid = NULL;
1040 struct p9_wstat wstat;
1041
1042 p9_debug(P9_DEBUG_VFS, "\n");
1043 retval = setattr_prepare(dentry, iattr);
1044 if (retval)
1045 return retval;
1046
1047 retval = -EPERM;
1048 v9ses = v9fs_dentry2v9ses(dentry);
1049 if (iattr->ia_valid & ATTR_FILE) {
1050 fid = iattr->ia_file->private_data;
1051 WARN_ON(!fid);
1052 }
1053 if (!fid)
1054 fid = v9fs_fid_lookup(dentry);
1055 if(IS_ERR(fid))
1056 return PTR_ERR(fid);
1057
1058 v9fs_blank_wstat(&wstat);
1059 if (iattr->ia_valid & ATTR_MODE)
1060 wstat.mode = unixmode2p9mode(v9ses, iattr->ia_mode);
1061
1062 if (iattr->ia_valid & ATTR_MTIME)
1063 wstat.mtime = iattr->ia_mtime.tv_sec;
1064
1065 if (iattr->ia_valid & ATTR_ATIME)
1066 wstat.atime = iattr->ia_atime.tv_sec;
1067
1068 if (iattr->ia_valid & ATTR_SIZE)
1069 wstat.length = iattr->ia_size;
1070
1071 if (v9fs_proto_dotu(v9ses)) {
1072 if (iattr->ia_valid & ATTR_UID)
1073 wstat.n_uid = iattr->ia_uid;
1074
1075 if (iattr->ia_valid & ATTR_GID)
1076 wstat.n_gid = iattr->ia_gid;
1077 }
1078
1079 /* Write all dirty data */
1080 if (d_is_reg(dentry))
1081 filemap_write_and_wait(d_inode(dentry)->i_mapping);
1082
1083 retval = p9_client_wstat(fid, &wstat);
1084 if (retval < 0)
1085 return retval;
1086
1087 if ((iattr->ia_valid & ATTR_SIZE) &&
1088 iattr->ia_size != i_size_read(d_inode(dentry)))
1089 truncate_setsize(d_inode(dentry), iattr->ia_size);
1090
1091 v9fs_invalidate_inode_attr(d_inode(dentry));
1092
1093 setattr_copy(d_inode(dentry), iattr);
1094 mark_inode_dirty(d_inode(dentry));
1095 return 0;
1096}
1097
1098/**
1099 * v9fs_stat2inode - populate an inode structure with mistat info
1100 * @stat: Plan 9 metadata (mistat) structure
1101 * @inode: inode to populate
1102 * @sb: superblock of filesystem
1103 * @flags: control flags (e.g. V9FS_STAT2INODE_KEEP_ISIZE)
1104 *
1105 */
1106
1107void
1108v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
1109 struct super_block *sb, unsigned int flags)
1110{
1111 umode_t mode;
1112 char ext[32];
1113 char tag_name[14];
1114 unsigned int i_nlink;
1115 struct v9fs_session_info *v9ses = sb->s_fs_info;
1116 struct v9fs_inode *v9inode = V9FS_I(inode);
1117
1118 set_nlink(inode, 1);
1119
1120 inode->i_atime.tv_sec = stat->atime;
1121 inode->i_mtime.tv_sec = stat->mtime;
1122 inode->i_ctime.tv_sec = stat->mtime;
1123
1124 inode->i_uid = v9ses->dfltuid;
1125 inode->i_gid = v9ses->dfltgid;
1126
1127 if (v9fs_proto_dotu(v9ses)) {
1128 inode->i_uid = stat->n_uid;
1129 inode->i_gid = stat->n_gid;
1130 }
1131 if ((S_ISREG(inode->i_mode)) || (S_ISDIR(inode->i_mode))) {
1132 if (v9fs_proto_dotu(v9ses) && (stat->extension[0] != '\0')) {
1133 /*
1134 * Hadlink support got added later to
1135 * to the .u extension. So there can be
1136 * server out there that doesn't support
1137 * this even with .u extension. So check
1138 * for non NULL stat->extension
1139 */
1140 strlcpy(ext, stat->extension, sizeof(ext));
1141 /* HARDLINKCOUNT %u */
1142 sscanf(ext, "%13s %u", tag_name, &i_nlink);
1143 if (!strncmp(tag_name, "HARDLINKCOUNT", 13))
1144 set_nlink(inode, i_nlink);
1145 }
1146 }
1147 mode = p9mode2perm(v9ses, stat);
1148 mode |= inode->i_mode & ~S_IALLUGO;
1149 inode->i_mode = mode;
1150
1151 if (!(flags & V9FS_STAT2INODE_KEEP_ISIZE))
1152 v9fs_i_size_write(inode, stat->length);
1153 /* not real number of blocks, but 512 byte ones ... */
1154 inode->i_blocks = (stat->length + 512 - 1) >> 9;
1155 v9inode->cache_validity &= ~V9FS_INO_INVALID_ATTR;
1156}
1157
1158/**
1159 * v9fs_qid2ino - convert qid into inode number
1160 * @qid: qid to hash
1161 *
1162 * BUG: potential for inode number collisions?
1163 */
1164
1165ino_t v9fs_qid2ino(struct p9_qid *qid)
1166{
1167 u64 path = qid->path + 2;
1168 ino_t i = 0;
1169
1170 if (sizeof(ino_t) == sizeof(path))
1171 memcpy(&i, &path, sizeof(ino_t));
1172 else
1173 i = (ino_t) (path ^ (path >> 32));
1174
1175 return i;
1176}
1177
1178/**
1179 * v9fs_vfs_get_link - follow a symlink path
1180 * @dentry: dentry for symlink
1181 * @inode: inode for symlink
1182 * @done: delayed call for when we are done with the return value
1183 */
1184
1185static const char *v9fs_vfs_get_link(struct dentry *dentry,
1186 struct inode *inode,
1187 struct delayed_call *done)
1188{
1189 struct v9fs_session_info *v9ses;
1190 struct p9_fid *fid;
1191 struct p9_wstat *st;
1192 char *res;
1193
1194 if (!dentry)
1195 return ERR_PTR(-ECHILD);
1196
1197 v9ses = v9fs_dentry2v9ses(dentry);
1198 fid = v9fs_fid_lookup(dentry);
1199 p9_debug(P9_DEBUG_VFS, "%pd\n", dentry);
1200
1201 if (IS_ERR(fid))
1202 return ERR_CAST(fid);
1203
1204 if (!v9fs_proto_dotu(v9ses))
1205 return ERR_PTR(-EBADF);
1206
1207 st = p9_client_stat(fid);
1208 if (IS_ERR(st))
1209 return ERR_CAST(st);
1210
1211 if (!(st->mode & P9_DMSYMLINK)) {
1212 p9stat_free(st);
1213 kfree(st);
1214 return ERR_PTR(-EINVAL);
1215 }
1216 res = st->extension;
1217 st->extension = NULL;
1218 if (strlen(res) >= PATH_MAX)
1219 res[PATH_MAX - 1] = '\0';
1220
1221 p9stat_free(st);
1222 kfree(st);
1223 set_delayed_call(done, kfree_link, res);
1224 return res;
1225}
1226
1227/**
1228 * v9fs_vfs_mkspecial - create a special file
1229 * @dir: inode to create special file in
1230 * @dentry: dentry to create
1231 * @perm: mode to create special file
1232 * @extension: 9p2000.u format extension string representing special file
1233 *
1234 */
1235
1236static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
1237 u32 perm, const char *extension)
1238{
1239 struct p9_fid *fid;
1240 struct v9fs_session_info *v9ses;
1241
1242 v9ses = v9fs_inode2v9ses(dir);
1243 if (!v9fs_proto_dotu(v9ses)) {
1244 p9_debug(P9_DEBUG_ERROR, "not extended\n");
1245 return -EPERM;
1246 }
1247
1248 fid = v9fs_create(v9ses, dir, dentry, (char *) extension, perm,
1249 P9_OREAD);
1250 if (IS_ERR(fid))
1251 return PTR_ERR(fid);
1252
1253 v9fs_invalidate_inode_attr(dir);
1254 p9_client_clunk(fid);
1255 return 0;
1256}
1257
1258/**
1259 * v9fs_vfs_symlink - helper function to create symlinks
1260 * @dir: directory inode containing symlink
1261 * @dentry: dentry for symlink
1262 * @symname: symlink data
1263 *
1264 * See Also: 9P2000.u RFC for more information
1265 *
1266 */
1267
1268static int
1269v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
1270{
1271 p9_debug(P9_DEBUG_VFS, " %lu,%pd,%s\n",
1272 dir->i_ino, dentry, symname);
1273
1274 return v9fs_vfs_mkspecial(dir, dentry, P9_DMSYMLINK, symname);
1275}
1276
1277#define U32_MAX_DIGITS 10
1278
1279/**
1280 * v9fs_vfs_link - create a hardlink
1281 * @old_dentry: dentry for file to link to
1282 * @dir: inode destination for new link
1283 * @dentry: dentry for link
1284 *
1285 */
1286
1287static int
1288v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
1289 struct dentry *dentry)
1290{
1291 int retval;
1292 char name[1 + U32_MAX_DIGITS + 2]; /* sign + number + \n + \0 */
1293 struct p9_fid *oldfid;
1294
1295 p9_debug(P9_DEBUG_VFS, " %lu,%pd,%pd\n",
1296 dir->i_ino, dentry, old_dentry);
1297
1298 oldfid = v9fs_fid_clone(old_dentry);
1299 if (IS_ERR(oldfid))
1300 return PTR_ERR(oldfid);
1301
1302 sprintf(name, "%d\n", oldfid->fid);
1303 retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name);
1304 if (!retval) {
1305 v9fs_refresh_inode(oldfid, d_inode(old_dentry));
1306 v9fs_invalidate_inode_attr(dir);
1307 }
1308 p9_client_clunk(oldfid);
1309 return retval;
1310}
1311
1312/**
1313 * v9fs_vfs_mknod - create a special file
1314 * @dir: inode destination for new link
1315 * @dentry: dentry for file
1316 * @mode: mode for creation
1317 * @rdev: device associated with special file
1318 *
1319 */
1320
1321static int
1322v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t rdev)
1323{
1324 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
1325 int retval;
1326 char name[2 + U32_MAX_DIGITS + 1 + U32_MAX_DIGITS + 1];
1327 u32 perm;
1328
1329 p9_debug(P9_DEBUG_VFS, " %lu,%pd mode: %hx MAJOR: %u MINOR: %u\n",
1330 dir->i_ino, dentry, mode,
1331 MAJOR(rdev), MINOR(rdev));
1332
1333 /* build extension */
1334 if (S_ISBLK(mode))
1335 sprintf(name, "b %u %u", MAJOR(rdev), MINOR(rdev));
1336 else if (S_ISCHR(mode))
1337 sprintf(name, "c %u %u", MAJOR(rdev), MINOR(rdev));
1338 else
1339 *name = 0;
1340
1341 perm = unixmode2p9mode(v9ses, mode);
1342 retval = v9fs_vfs_mkspecial(dir, dentry, perm, name);
1343
1344 return retval;
1345}
1346
1347int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode)
1348{
1349 int umode;
1350 dev_t rdev;
1351 struct p9_wstat *st;
1352 struct v9fs_session_info *v9ses;
1353 unsigned int flags;
1354
1355 v9ses = v9fs_inode2v9ses(inode);
1356 st = p9_client_stat(fid);
1357 if (IS_ERR(st))
1358 return PTR_ERR(st);
1359 /*
1360 * Don't update inode if the file type is different
1361 */
1362 umode = p9mode2unixmode(v9ses, st, &rdev);
1363 if ((inode->i_mode & S_IFMT) != (umode & S_IFMT))
1364 goto out;
1365
1366 /*
1367 * We don't want to refresh inode->i_size,
1368 * because we may have cached data
1369 */
1370 flags = (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) ?
1371 V9FS_STAT2INODE_KEEP_ISIZE : 0;
1372 v9fs_stat2inode(st, inode, inode->i_sb, flags);
1373out:
1374 p9stat_free(st);
1375 kfree(st);
1376 return 0;
1377}
1378
1379static const struct inode_operations v9fs_dir_inode_operations_dotu = {
1380 .create = v9fs_vfs_create,
1381 .lookup = v9fs_vfs_lookup,
1382 .atomic_open = v9fs_vfs_atomic_open,
1383 .symlink = v9fs_vfs_symlink,
1384 .link = v9fs_vfs_link,
1385 .unlink = v9fs_vfs_unlink,
1386 .mkdir = v9fs_vfs_mkdir,
1387 .rmdir = v9fs_vfs_rmdir,
1388 .mknod = v9fs_vfs_mknod,
1389 .rename = v9fs_vfs_rename,
1390 .getattr = v9fs_vfs_getattr,
1391 .setattr = v9fs_vfs_setattr,
1392};
1393
1394static const struct inode_operations v9fs_dir_inode_operations = {
1395 .create = v9fs_vfs_create,
1396 .lookup = v9fs_vfs_lookup,
1397 .atomic_open = v9fs_vfs_atomic_open,
1398 .unlink = v9fs_vfs_unlink,
1399 .mkdir = v9fs_vfs_mkdir,
1400 .rmdir = v9fs_vfs_rmdir,
1401 .mknod = v9fs_vfs_mknod,
1402 .rename = v9fs_vfs_rename,
1403 .getattr = v9fs_vfs_getattr,
1404 .setattr = v9fs_vfs_setattr,
1405};
1406
1407static const struct inode_operations v9fs_file_inode_operations = {
1408 .getattr = v9fs_vfs_getattr,
1409 .setattr = v9fs_vfs_setattr,
1410};
1411
1412static const struct inode_operations v9fs_symlink_inode_operations = {
1413 .get_link = v9fs_vfs_get_link,
1414 .getattr = v9fs_vfs_getattr,
1415 .setattr = v9fs_vfs_setattr,
1416};
1417