1 // SPDX-License-Identifier: GPL-2.0-only
3 * This file contains vfs inode ops for the 9P2000.L protocol.
5 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
6 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
9 #include <linux/module.h>
10 #include <linux/errno.h>
12 #include <linux/file.h>
13 #include <linux/pagemap.h>
14 #include <linux/stat.h>
15 #include <linux/string.h>
16 #include <linux/inet.h>
17 #include <linux/namei.h>
18 #include <linux/idr.h>
19 #include <linux/sched.h>
20 #include <linux/slab.h>
21 #include <linux/xattr.h>
22 #include <linux/posix_acl.h>
23 #include <net/9p/9p.h>
24 #include <net/9p/client.h>
34 v9fs_vfs_mknod_dotl(struct user_namespace *mnt_userns, struct inode *dir,
35 struct dentry *dentry, umode_t omode, dev_t rdev);
38 * v9fs_get_fsgid_for_create - Helper function to get the gid for a new object
39 * @dir_inode: The directory inode
41 * Helper function to get the gid for creating a
42 * new file system object. This checks the S_ISGID to determine the owning
43 * group of the new file system object.
46 static kgid_t v9fs_get_fsgid_for_create(struct inode *dir_inode)
48 BUG_ON(dir_inode == NULL);
50 if (dir_inode->i_mode & S_ISGID) {
51 /* set_gid bit is set.*/
52 return dir_inode->i_gid;
54 return current_fsgid();
57 static int v9fs_test_inode_dotl(struct inode *inode, void *data)
59 struct v9fs_inode *v9inode = V9FS_I(inode);
60 struct p9_stat_dotl *st = (struct p9_stat_dotl *)data;
62 /* don't match inode of different type */
63 if (inode_wrong_type(inode, st->st_mode))
66 if (inode->i_generation != st->st_gen)
69 /* compare qid details */
70 if (memcmp(&v9inode->qid.version,
71 &st->qid.version, sizeof(v9inode->qid.version)))
74 if (v9inode->qid.type != st->qid.type)
77 if (v9inode->qid.path != st->qid.path)
82 /* Always get a new inode */
83 static int v9fs_test_new_inode_dotl(struct inode *inode, void *data)
88 static int v9fs_set_inode_dotl(struct inode *inode, void *data)
90 struct v9fs_inode *v9inode = V9FS_I(inode);
91 struct p9_stat_dotl *st = (struct p9_stat_dotl *)data;
93 memcpy(&v9inode->qid, &st->qid, sizeof(st->qid));
94 inode->i_generation = st->st_gen;
98 static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,
101 struct p9_stat_dotl *st,
107 struct v9fs_session_info *v9ses = sb->s_fs_info;
108 int (*test)(struct inode *inode, void *data);
111 test = v9fs_test_new_inode_dotl;
113 test = v9fs_test_inode_dotl;
115 i_ino = v9fs_qid2ino(qid);
116 inode = iget5_locked(sb, i_ino, test, v9fs_set_inode_dotl, st);
118 return ERR_PTR(-ENOMEM);
119 if (!(inode->i_state & I_NEW))
122 * initialize the inode with the stat info
123 * FIXME!! we may need support for stale inodes
126 inode->i_ino = i_ino;
127 retval = v9fs_init_inode(v9ses, inode,
128 st->st_mode, new_decode_dev(st->st_rdev));
132 v9fs_stat2inode_dotl(st, inode, 0);
133 v9fs_set_netfs_context(inode);
134 v9fs_cache_inode_get_cookie(inode);
135 retval = v9fs_get_acl(inode, fid);
139 unlock_new_inode(inode);
143 return ERR_PTR(retval);
148 v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid,
149 struct super_block *sb, int new)
151 struct p9_stat_dotl *st;
152 struct inode *inode = NULL;
154 st = p9_client_getattr_dotl(fid, P9_STATS_BASIC | P9_STATS_GEN);
158 inode = v9fs_qid_iget_dotl(sb, &st->qid, fid, st, new);
163 struct dotl_openflag_map {
168 static int v9fs_mapped_dotl_flags(int flags)
172 struct dotl_openflag_map dotl_oflag_map[] = {
173 { O_CREAT, P9_DOTL_CREATE },
174 { O_EXCL, P9_DOTL_EXCL },
175 { O_NOCTTY, P9_DOTL_NOCTTY },
176 { O_APPEND, P9_DOTL_APPEND },
177 { O_NONBLOCK, P9_DOTL_NONBLOCK },
178 { O_DSYNC, P9_DOTL_DSYNC },
179 { FASYNC, P9_DOTL_FASYNC },
180 { O_DIRECT, P9_DOTL_DIRECT },
181 { O_LARGEFILE, P9_DOTL_LARGEFILE },
182 { O_DIRECTORY, P9_DOTL_DIRECTORY },
183 { O_NOFOLLOW, P9_DOTL_NOFOLLOW },
184 { O_NOATIME, P9_DOTL_NOATIME },
185 { O_CLOEXEC, P9_DOTL_CLOEXEC },
186 { O_SYNC, P9_DOTL_SYNC},
188 for (i = 0; i < ARRAY_SIZE(dotl_oflag_map); i++) {
189 if (flags & dotl_oflag_map[i].open_flag)
190 rflags |= dotl_oflag_map[i].dotl_flag;
196 * v9fs_open_to_dotl_flags- convert Linux specific open flags to
198 * @flags: flags to convert
200 int v9fs_open_to_dotl_flags(int flags)
205 * We have same bits for P9_DOTL_READONLY, P9_DOTL_WRONLY
206 * and P9_DOTL_NOACCESS
208 rflags |= flags & O_ACCMODE;
209 rflags |= v9fs_mapped_dotl_flags(flags);
215 * v9fs_vfs_create_dotl - VFS hook to create files for 9P2000.L protocol.
216 * @mnt_userns: The user namespace of the mount
217 * @dir: directory inode that is being created
218 * @dentry: dentry that is being deleted
219 * @omode: create permissions
220 * @excl: True if the file must not yet exist
224 v9fs_vfs_create_dotl(struct user_namespace *mnt_userns, struct inode *dir,
225 struct dentry *dentry, umode_t omode, bool excl)
227 return v9fs_vfs_mknod_dotl(mnt_userns, dir, dentry, omode, 0);
231 v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,
232 struct file *file, unsigned int flags, umode_t omode)
237 const unsigned char *name = NULL;
240 struct p9_fid *fid = NULL;
241 struct v9fs_inode *v9inode;
242 struct p9_fid *dfid = NULL, *ofid = NULL, *inode_fid = NULL;
243 struct v9fs_session_info *v9ses;
244 struct posix_acl *pacl = NULL, *dacl = NULL;
245 struct dentry *res = NULL;
247 if (d_in_lookup(dentry)) {
248 res = v9fs_vfs_lookup(dir, dentry, 0);
257 if (!(flags & O_CREAT) || d_really_is_positive(dentry))
258 return finish_no_open(file, res);
260 v9ses = v9fs_inode2v9ses(dir);
262 name = dentry->d_name.name;
263 p9_debug(P9_DEBUG_VFS, "name:%s flags:0x%x mode:0x%x\n",
266 dfid = v9fs_parent_fid(dentry);
269 p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
273 /* clone a fid to use for creation */
274 ofid = clone_fid(dfid);
277 p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
281 gid = v9fs_get_fsgid_for_create(dir);
284 /* Update mode based on ACL value */
285 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
287 p9_debug(P9_DEBUG_VFS, "Failed to get acl values in creat %d\n",
291 err = p9_client_create_dotl(ofid, name, v9fs_open_to_dotl_flags(flags),
294 p9_debug(P9_DEBUG_VFS, "p9_client_open_dotl failed in creat %d\n",
298 v9fs_invalidate_inode_attr(dir);
300 /* instantiate inode and assign the unopened fid to the dentry */
301 fid = p9_client_walk(dfid, 1, &name, 1);
304 p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
307 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
309 err = PTR_ERR(inode);
310 p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n", err);
313 /* Now set the ACL based on the default value */
314 v9fs_set_create_acl(inode, fid, dacl, pacl);
316 v9fs_fid_add(dentry, &fid);
317 d_instantiate(dentry, inode);
319 v9inode = V9FS_I(inode);
320 mutex_lock(&v9inode->v_mutex);
321 if ((v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) &&
322 !v9inode->writeback_fid &&
323 ((flags & O_ACCMODE) != O_RDONLY)) {
325 * clone a fid and add it to writeback_fid
326 * we do it during open time instead of
327 * page dirty time via write_begin/page_mkwrite
328 * because we want write after unlink usecase
331 inode_fid = v9fs_writeback_fid(dentry);
332 if (IS_ERR(inode_fid)) {
333 err = PTR_ERR(inode_fid);
334 mutex_unlock(&v9inode->v_mutex);
337 v9inode->writeback_fid = (void *) inode_fid;
339 mutex_unlock(&v9inode->v_mutex);
340 /* Since we are opening a file, assign the open fid to the file */
341 err = finish_open(file, dentry, generic_file_open);
344 file->private_data = ofid;
345 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
346 fscache_use_cookie(v9fs_inode_cookie(v9inode),
347 file->f_mode & FMODE_WRITE);
348 v9fs_open_fid_add(inode, &ofid);
349 file->f_mode |= FMODE_CREATED;
354 v9fs_put_acl(dacl, pacl);
360 * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory
361 * @mnt_userns: The user namespace of the mount
362 * @dir: inode that is being unlinked
363 * @dentry: dentry that is being unlinked
364 * @omode: mode for new directory
368 static int v9fs_vfs_mkdir_dotl(struct user_namespace *mnt_userns,
369 struct inode *dir, struct dentry *dentry,
373 struct v9fs_session_info *v9ses;
374 struct p9_fid *fid = NULL, *dfid = NULL;
376 const unsigned char *name;
380 struct posix_acl *dacl = NULL, *pacl = NULL;
382 p9_debug(P9_DEBUG_VFS, "name %pd\n", dentry);
384 v9ses = v9fs_inode2v9ses(dir);
387 if (dir->i_mode & S_ISGID)
390 dfid = v9fs_parent_fid(dentry);
393 p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
397 gid = v9fs_get_fsgid_for_create(dir);
399 /* Update mode based on ACL value */
400 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
402 p9_debug(P9_DEBUG_VFS, "Failed to get acl values in mkdir %d\n",
406 name = dentry->d_name.name;
407 err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid);
410 fid = p9_client_walk(dfid, 1, &name, 1);
413 p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
418 /* instantiate inode and assign the unopened fid to the dentry */
419 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
420 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
422 err = PTR_ERR(inode);
423 p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",
427 v9fs_fid_add(dentry, &fid);
428 v9fs_set_create_acl(inode, fid, dacl, pacl);
429 d_instantiate(dentry, inode);
433 * Not in cached mode. No need to populate
434 * inode with stat. We need to get an inode
435 * so that we can set the acl with dentry
437 inode = v9fs_get_inode(dir->i_sb, mode, 0);
439 err = PTR_ERR(inode);
442 v9fs_set_create_acl(inode, fid, dacl, pacl);
443 d_instantiate(dentry, inode);
446 v9fs_invalidate_inode_attr(dir);
449 v9fs_put_acl(dacl, pacl);
455 v9fs_vfs_getattr_dotl(struct user_namespace *mnt_userns,
456 const struct path *path, struct kstat *stat,
457 u32 request_mask, unsigned int flags)
459 struct dentry *dentry = path->dentry;
460 struct v9fs_session_info *v9ses;
462 struct p9_stat_dotl *st;
464 p9_debug(P9_DEBUG_VFS, "dentry: %p\n", dentry);
465 v9ses = v9fs_dentry2v9ses(dentry);
466 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
467 generic_fillattr(&init_user_ns, d_inode(dentry), stat);
470 fid = v9fs_fid_lookup(dentry);
474 /* Ask for all the fields in stat structure. Server will return
475 * whatever it supports
478 st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
483 v9fs_stat2inode_dotl(st, d_inode(dentry), 0);
484 generic_fillattr(&init_user_ns, d_inode(dentry), stat);
485 /* Change block size to what the server returned */
486 stat->blksize = st->st_blksize;
495 #define P9_ATTR_MODE (1 << 0)
496 #define P9_ATTR_UID (1 << 1)
497 #define P9_ATTR_GID (1 << 2)
498 #define P9_ATTR_SIZE (1 << 3)
499 #define P9_ATTR_ATIME (1 << 4)
500 #define P9_ATTR_MTIME (1 << 5)
501 #define P9_ATTR_CTIME (1 << 6)
502 #define P9_ATTR_ATIME_SET (1 << 7)
503 #define P9_ATTR_MTIME_SET (1 << 8)
505 struct dotl_iattr_map {
510 static int v9fs_mapped_iattr_valid(int iattr_valid)
513 int p9_iattr_valid = 0;
514 struct dotl_iattr_map dotl_iattr_map[] = {
515 { ATTR_MODE, P9_ATTR_MODE },
516 { ATTR_UID, P9_ATTR_UID },
517 { ATTR_GID, P9_ATTR_GID },
518 { ATTR_SIZE, P9_ATTR_SIZE },
519 { ATTR_ATIME, P9_ATTR_ATIME },
520 { ATTR_MTIME, P9_ATTR_MTIME },
521 { ATTR_CTIME, P9_ATTR_CTIME },
522 { ATTR_ATIME_SET, P9_ATTR_ATIME_SET },
523 { ATTR_MTIME_SET, P9_ATTR_MTIME_SET },
525 for (i = 0; i < ARRAY_SIZE(dotl_iattr_map); i++) {
526 if (iattr_valid & dotl_iattr_map[i].iattr_valid)
527 p9_iattr_valid |= dotl_iattr_map[i].p9_iattr_valid;
529 return p9_iattr_valid;
533 * v9fs_vfs_setattr_dotl - set file metadata
534 * @mnt_userns: The user namespace of the mount
535 * @dentry: file whose metadata to set
536 * @iattr: metadata assignment structure
540 int v9fs_vfs_setattr_dotl(struct user_namespace *mnt_userns,
541 struct dentry *dentry, struct iattr *iattr)
543 int retval, use_dentry = 0;
544 struct p9_fid *fid = NULL;
545 struct p9_iattr_dotl p9attr = {
549 struct inode *inode = d_inode(dentry);
551 p9_debug(P9_DEBUG_VFS, "\n");
553 retval = setattr_prepare(&init_user_ns, dentry, iattr);
557 p9attr.valid = v9fs_mapped_iattr_valid(iattr->ia_valid);
558 if (iattr->ia_valid & ATTR_MODE)
559 p9attr.mode = iattr->ia_mode;
560 if (iattr->ia_valid & ATTR_UID)
561 p9attr.uid = iattr->ia_uid;
562 if (iattr->ia_valid & ATTR_GID)
563 p9attr.gid = iattr->ia_gid;
564 if (iattr->ia_valid & ATTR_SIZE)
565 p9attr.size = iattr->ia_size;
566 if (iattr->ia_valid & ATTR_ATIME_SET) {
567 p9attr.atime_sec = iattr->ia_atime.tv_sec;
568 p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
570 if (iattr->ia_valid & ATTR_MTIME_SET) {
571 p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
572 p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
575 if (iattr->ia_valid & ATTR_FILE) {
576 fid = iattr->ia_file->private_data;
580 fid = v9fs_fid_lookup(dentry);
586 /* Write all dirty data */
587 if (S_ISREG(inode->i_mode))
588 filemap_write_and_wait(inode->i_mapping);
590 retval = p9_client_setattr(fid, &p9attr);
597 if ((iattr->ia_valid & ATTR_SIZE) &&
598 iattr->ia_size != i_size_read(inode))
599 truncate_setsize(inode, iattr->ia_size);
601 v9fs_invalidate_inode_attr(inode);
602 setattr_copy(&init_user_ns, inode, iattr);
603 mark_inode_dirty(inode);
604 if (iattr->ia_valid & ATTR_MODE) {
605 /* We also want to update ACL when we update mode bits */
606 retval = v9fs_acl_chmod(inode, fid);
620 * v9fs_stat2inode_dotl - populate an inode structure with stat info
621 * @stat: stat structure
622 * @inode: inode to populate
623 * @flags: ctrl flags (e.g. V9FS_STAT2INODE_KEEP_ISIZE)
628 v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode,
632 struct v9fs_inode *v9inode = V9FS_I(inode);
634 if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) {
635 inode->i_atime.tv_sec = stat->st_atime_sec;
636 inode->i_atime.tv_nsec = stat->st_atime_nsec;
637 inode->i_mtime.tv_sec = stat->st_mtime_sec;
638 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
639 inode->i_ctime.tv_sec = stat->st_ctime_sec;
640 inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
641 inode->i_uid = stat->st_uid;
642 inode->i_gid = stat->st_gid;
643 set_nlink(inode, stat->st_nlink);
645 mode = stat->st_mode & S_IALLUGO;
646 mode |= inode->i_mode & ~S_IALLUGO;
647 inode->i_mode = mode;
649 if (!(flags & V9FS_STAT2INODE_KEEP_ISIZE))
650 v9fs_i_size_write(inode, stat->st_size);
651 inode->i_blocks = stat->st_blocks;
653 if (stat->st_result_mask & P9_STATS_ATIME) {
654 inode->i_atime.tv_sec = stat->st_atime_sec;
655 inode->i_atime.tv_nsec = stat->st_atime_nsec;
657 if (stat->st_result_mask & P9_STATS_MTIME) {
658 inode->i_mtime.tv_sec = stat->st_mtime_sec;
659 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
661 if (stat->st_result_mask & P9_STATS_CTIME) {
662 inode->i_ctime.tv_sec = stat->st_ctime_sec;
663 inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
665 if (stat->st_result_mask & P9_STATS_UID)
666 inode->i_uid = stat->st_uid;
667 if (stat->st_result_mask & P9_STATS_GID)
668 inode->i_gid = stat->st_gid;
669 if (stat->st_result_mask & P9_STATS_NLINK)
670 set_nlink(inode, stat->st_nlink);
671 if (stat->st_result_mask & P9_STATS_MODE) {
672 mode = stat->st_mode & S_IALLUGO;
673 mode |= inode->i_mode & ~S_IALLUGO;
674 inode->i_mode = mode;
676 if (!(flags & V9FS_STAT2INODE_KEEP_ISIZE) &&
677 stat->st_result_mask & P9_STATS_SIZE)
678 v9fs_i_size_write(inode, stat->st_size);
679 if (stat->st_result_mask & P9_STATS_BLOCKS)
680 inode->i_blocks = stat->st_blocks;
682 if (stat->st_result_mask & P9_STATS_GEN)
683 inode->i_generation = stat->st_gen;
685 /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION
686 * because the inode structure does not have fields for them.
688 v9inode->cache_validity &= ~V9FS_INO_INVALID_ATTR;
692 v9fs_vfs_symlink_dotl(struct user_namespace *mnt_userns, struct inode *dir,
693 struct dentry *dentry, const char *symname)
697 const unsigned char *name;
701 struct p9_fid *fid = NULL;
702 struct v9fs_session_info *v9ses;
704 name = dentry->d_name.name;
705 p9_debug(P9_DEBUG_VFS, "%lu,%s,%s\n", dir->i_ino, name, symname);
706 v9ses = v9fs_inode2v9ses(dir);
708 dfid = v9fs_parent_fid(dentry);
711 p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
715 gid = v9fs_get_fsgid_for_create(dir);
717 /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */
718 err = p9_client_symlink(dfid, name, symname, gid, &qid);
721 p9_debug(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err);
725 v9fs_invalidate_inode_attr(dir);
726 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
727 /* Now walk from the parent so we can get an unopened fid. */
728 fid = p9_client_walk(dfid, 1, &name, 1);
731 p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
736 /* instantiate inode and assign the unopened fid to dentry */
737 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
739 err = PTR_ERR(inode);
740 p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",
744 v9fs_fid_add(dentry, &fid);
745 d_instantiate(dentry, inode);
748 /* Not in cached mode. No need to populate inode with stat */
749 inode = v9fs_get_inode(dir->i_sb, S_IFLNK, 0);
751 err = PTR_ERR(inode);
754 d_instantiate(dentry, inode);
764 * v9fs_vfs_link_dotl - create a hardlink for dotl
765 * @old_dentry: dentry for file to link to
766 * @dir: inode destination for new link
767 * @dentry: dentry for link
772 v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
773 struct dentry *dentry)
776 struct p9_fid *dfid, *oldfid;
777 struct v9fs_session_info *v9ses;
779 p9_debug(P9_DEBUG_VFS, "dir ino: %lu, old_name: %pd, new_name: %pd\n",
780 dir->i_ino, old_dentry, dentry);
782 v9ses = v9fs_inode2v9ses(dir);
783 dfid = v9fs_parent_fid(dentry);
785 return PTR_ERR(dfid);
787 oldfid = v9fs_fid_lookup(old_dentry);
788 if (IS_ERR(oldfid)) {
790 return PTR_ERR(oldfid);
793 err = p9_client_link(dfid, oldfid, dentry->d_name.name);
798 p9_debug(P9_DEBUG_VFS, "p9_client_link failed %d\n", err);
802 v9fs_invalidate_inode_attr(dir);
803 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
804 /* Get the latest stat info from server. */
807 fid = v9fs_fid_lookup(old_dentry);
811 v9fs_refresh_inode_dotl(fid, d_inode(old_dentry));
814 ihold(d_inode(old_dentry));
815 d_instantiate(dentry, d_inode(old_dentry));
821 * v9fs_vfs_mknod_dotl - create a special file
822 * @mnt_userns: The user namespace of the mount
823 * @dir: inode destination for new link
824 * @dentry: dentry for file
825 * @omode: mode for creation
826 * @rdev: device associated with special file
830 v9fs_vfs_mknod_dotl(struct user_namespace *mnt_userns, struct inode *dir,
831 struct dentry *dentry, umode_t omode, dev_t rdev)
835 const unsigned char *name;
837 struct v9fs_session_info *v9ses;
838 struct p9_fid *fid = NULL, *dfid = NULL;
841 struct posix_acl *dacl = NULL, *pacl = NULL;
843 p9_debug(P9_DEBUG_VFS, " %lu,%pd mode: %x MAJOR: %u MINOR: %u\n",
844 dir->i_ino, dentry, omode,
845 MAJOR(rdev), MINOR(rdev));
847 v9ses = v9fs_inode2v9ses(dir);
848 dfid = v9fs_parent_fid(dentry);
851 p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
855 gid = v9fs_get_fsgid_for_create(dir);
857 /* Update mode based on ACL value */
858 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
860 p9_debug(P9_DEBUG_VFS, "Failed to get acl values in mknod %d\n",
864 name = dentry->d_name.name;
866 err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid);
870 v9fs_invalidate_inode_attr(dir);
871 fid = p9_client_walk(dfid, 1, &name, 1);
874 p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
879 /* instantiate inode and assign the unopened fid to the dentry */
880 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
881 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
883 err = PTR_ERR(inode);
884 p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",
888 v9fs_set_create_acl(inode, fid, dacl, pacl);
889 v9fs_fid_add(dentry, &fid);
890 d_instantiate(dentry, inode);
894 * Not in cached mode. No need to populate inode with stat.
895 * socket syscall returns a fd, so we need instantiate
897 inode = v9fs_get_inode(dir->i_sb, mode, rdev);
899 err = PTR_ERR(inode);
902 v9fs_set_create_acl(inode, fid, dacl, pacl);
903 d_instantiate(dentry, inode);
907 v9fs_put_acl(dacl, pacl);
914 * v9fs_vfs_get_link_dotl - follow a symlink path
915 * @dentry: dentry for symlink
916 * @inode: inode for symlink
917 * @done: destructor for return value
921 v9fs_vfs_get_link_dotl(struct dentry *dentry,
923 struct delayed_call *done)
930 return ERR_PTR(-ECHILD);
932 p9_debug(P9_DEBUG_VFS, "%pd\n", dentry);
934 fid = v9fs_fid_lookup(dentry);
936 return ERR_CAST(fid);
937 retval = p9_client_readlink(fid, &target);
940 return ERR_PTR(retval);
941 set_delayed_call(done, kfree_link, target);
945 int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode)
947 struct p9_stat_dotl *st;
948 struct v9fs_session_info *v9ses;
951 v9ses = v9fs_inode2v9ses(inode);
952 st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
956 * Don't update inode if the file type is different
958 if (inode_wrong_type(inode, st->st_mode))
962 * We don't want to refresh inode->i_size,
963 * because we may have cached data
965 flags = (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) ?
966 V9FS_STAT2INODE_KEEP_ISIZE : 0;
967 v9fs_stat2inode_dotl(st, inode, flags);
973 const struct inode_operations v9fs_dir_inode_operations_dotl = {
974 .create = v9fs_vfs_create_dotl,
975 .atomic_open = v9fs_vfs_atomic_open_dotl,
976 .lookup = v9fs_vfs_lookup,
977 .link = v9fs_vfs_link_dotl,
978 .symlink = v9fs_vfs_symlink_dotl,
979 .unlink = v9fs_vfs_unlink,
980 .mkdir = v9fs_vfs_mkdir_dotl,
981 .rmdir = v9fs_vfs_rmdir,
982 .mknod = v9fs_vfs_mknod_dotl,
983 .rename = v9fs_vfs_rename,
984 .getattr = v9fs_vfs_getattr_dotl,
985 .setattr = v9fs_vfs_setattr_dotl,
986 .listxattr = v9fs_listxattr,
987 .get_acl = v9fs_iop_get_acl,
990 const struct inode_operations v9fs_file_inode_operations_dotl = {
991 .getattr = v9fs_vfs_getattr_dotl,
992 .setattr = v9fs_vfs_setattr_dotl,
993 .listxattr = v9fs_listxattr,
994 .get_acl = v9fs_iop_get_acl,
997 const struct inode_operations v9fs_symlink_inode_operations_dotl = {
998 .get_link = v9fs_vfs_get_link_dotl,
999 .getattr = v9fs_vfs_getattr_dotl,
1000 .setattr = v9fs_vfs_setattr_dotl,
1001 .listxattr = v9fs_listxattr,