1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/fs/9p/vfs_inode_dotl.c
5 * This file contains vfs inode ops for the 9P2000.L protocol.
7 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
8 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
11 #include <linux/module.h>
12 #include <linux/errno.h>
14 #include <linux/file.h>
15 #include <linux/pagemap.h>
16 #include <linux/stat.h>
17 #include <linux/string.h>
18 #include <linux/inet.h>
19 #include <linux/namei.h>
20 #include <linux/idr.h>
21 #include <linux/sched.h>
22 #include <linux/slab.h>
23 #include <linux/xattr.h>
24 #include <linux/posix_acl.h>
25 #include <net/9p/9p.h>
26 #include <net/9p/client.h>
36 v9fs_vfs_mknod_dotl(struct user_namespace *mnt_userns, struct inode *dir,
37 struct dentry *dentry, umode_t omode, dev_t rdev);
40 * v9fs_get_fsgid_for_create - Helper function to get the gid for a new object
41 * @dir_inode: The directory inode
43 * Helper function to get the gid for creating a
44 * new file system object. This checks the S_ISGID to determine the owning
45 * group of the new file system object.
48 static kgid_t v9fs_get_fsgid_for_create(struct inode *dir_inode)
50 BUG_ON(dir_inode == NULL);
52 if (dir_inode->i_mode & S_ISGID) {
53 /* set_gid bit is set.*/
54 return dir_inode->i_gid;
56 return current_fsgid();
59 static int v9fs_test_inode_dotl(struct inode *inode, void *data)
61 struct v9fs_inode *v9inode = V9FS_I(inode);
62 struct p9_stat_dotl *st = (struct p9_stat_dotl *)data;
64 /* don't match inode of different type */
65 if (inode_wrong_type(inode, st->st_mode))
68 if (inode->i_generation != st->st_gen)
71 /* compare qid details */
72 if (memcmp(&v9inode->qid.version,
73 &st->qid.version, sizeof(v9inode->qid.version)))
76 if (v9inode->qid.type != st->qid.type)
79 if (v9inode->qid.path != st->qid.path)
84 /* Always get a new inode */
85 static int v9fs_test_new_inode_dotl(struct inode *inode, void *data)
90 static int v9fs_set_inode_dotl(struct inode *inode, void *data)
92 struct v9fs_inode *v9inode = V9FS_I(inode);
93 struct p9_stat_dotl *st = (struct p9_stat_dotl *)data;
95 memcpy(&v9inode->qid, &st->qid, sizeof(st->qid));
96 inode->i_generation = st->st_gen;
100 static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,
103 struct p9_stat_dotl *st,
109 struct v9fs_session_info *v9ses = sb->s_fs_info;
110 int (*test)(struct inode *inode, void *data);
113 test = v9fs_test_new_inode_dotl;
115 test = v9fs_test_inode_dotl;
117 i_ino = v9fs_qid2ino(qid);
118 inode = iget5_locked(sb, i_ino, test, v9fs_set_inode_dotl, st);
120 return ERR_PTR(-ENOMEM);
121 if (!(inode->i_state & I_NEW))
124 * initialize the inode with the stat info
125 * FIXME!! we may need support for stale inodes
128 inode->i_ino = i_ino;
129 retval = v9fs_init_inode(v9ses, inode,
130 st->st_mode, new_decode_dev(st->st_rdev));
134 v9fs_stat2inode_dotl(st, inode, 0);
135 v9fs_cache_inode_get_cookie(inode);
136 retval = v9fs_get_acl(inode, fid);
140 unlock_new_inode(inode);
144 return ERR_PTR(retval);
149 v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid,
150 struct super_block *sb, int new)
152 struct p9_stat_dotl *st;
153 struct inode *inode = NULL;
155 st = p9_client_getattr_dotl(fid, P9_STATS_BASIC | P9_STATS_GEN);
159 inode = v9fs_qid_iget_dotl(sb, &st->qid, fid, st, new);
164 struct dotl_openflag_map {
169 static int v9fs_mapped_dotl_flags(int flags)
173 struct dotl_openflag_map dotl_oflag_map[] = {
174 { O_CREAT, P9_DOTL_CREATE },
175 { O_EXCL, P9_DOTL_EXCL },
176 { O_NOCTTY, P9_DOTL_NOCTTY },
177 { O_APPEND, P9_DOTL_APPEND },
178 { O_NONBLOCK, P9_DOTL_NONBLOCK },
179 { O_DSYNC, P9_DOTL_DSYNC },
180 { FASYNC, P9_DOTL_FASYNC },
181 { O_DIRECT, P9_DOTL_DIRECT },
182 { O_LARGEFILE, P9_DOTL_LARGEFILE },
183 { O_DIRECTORY, P9_DOTL_DIRECTORY },
184 { O_NOFOLLOW, P9_DOTL_NOFOLLOW },
185 { O_NOATIME, P9_DOTL_NOATIME },
186 { O_CLOEXEC, P9_DOTL_CLOEXEC },
187 { O_SYNC, P9_DOTL_SYNC},
189 for (i = 0; i < ARRAY_SIZE(dotl_oflag_map); i++) {
190 if (flags & dotl_oflag_map[i].open_flag)
191 rflags |= dotl_oflag_map[i].dotl_flag;
197 * v9fs_open_to_dotl_flags- convert Linux specific open flags to
199 * @flags: flags to convert
201 int v9fs_open_to_dotl_flags(int flags)
206 * We have same bits for P9_DOTL_READONLY, P9_DOTL_WRONLY
207 * and P9_DOTL_NOACCESS
209 rflags |= flags & O_ACCMODE;
210 rflags |= v9fs_mapped_dotl_flags(flags);
216 * v9fs_vfs_create_dotl - VFS hook to create files for 9P2000.L protocol.
217 * @mnt_userns: The user namespace of the mount
218 * @dir: directory inode that is being created
219 * @dentry: dentry that is being deleted
220 * @omode: create permissions
221 * @excl: True if the file must not yet exist
225 v9fs_vfs_create_dotl(struct user_namespace *mnt_userns, struct inode *dir,
226 struct dentry *dentry, umode_t omode, bool excl)
228 return v9fs_vfs_mknod_dotl(mnt_userns, dir, dentry, omode, 0);
232 v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,
233 struct file *file, unsigned int flags, umode_t omode)
238 const unsigned char *name = NULL;
241 struct p9_fid *fid = NULL;
242 struct v9fs_inode *v9inode;
243 struct p9_fid *dfid, *ofid, *inode_fid;
244 struct v9fs_session_info *v9ses;
245 struct posix_acl *pacl = NULL, *dacl = NULL;
246 struct dentry *res = NULL;
248 if (d_in_lookup(dentry)) {
249 res = v9fs_vfs_lookup(dir, dentry, 0);
258 if (!(flags & O_CREAT) || d_really_is_positive(dentry))
259 return finish_no_open(file, res);
261 v9ses = v9fs_inode2v9ses(dir);
263 name = dentry->d_name.name;
264 p9_debug(P9_DEBUG_VFS, "name:%s flags:0x%x mode:0x%x\n",
267 dfid = v9fs_parent_fid(dentry);
270 p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
274 /* clone a fid to use for creation */
275 ofid = clone_fid(dfid);
278 p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
279 p9_client_clunk(dfid);
283 gid = v9fs_get_fsgid_for_create(dir);
286 /* Update mode based on ACL value */
287 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
289 p9_debug(P9_DEBUG_VFS, "Failed to get acl values in creat %d\n",
291 p9_client_clunk(dfid);
294 err = p9_client_create_dotl(ofid, name, v9fs_open_to_dotl_flags(flags),
297 p9_debug(P9_DEBUG_VFS, "p9_client_open_dotl failed in creat %d\n",
299 p9_client_clunk(dfid);
302 v9fs_invalidate_inode_attr(dir);
304 /* instantiate inode and assign the unopened fid to the dentry */
305 fid = p9_client_walk(dfid, 1, &name, 1);
306 p9_client_clunk(dfid);
309 p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
313 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
315 err = PTR_ERR(inode);
316 p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n", err);
319 /* Now set the ACL based on the default value */
320 v9fs_set_create_acl(inode, fid, dacl, pacl);
322 v9fs_fid_add(dentry, fid);
323 d_instantiate(dentry, inode);
325 v9inode = V9FS_I(inode);
326 mutex_lock(&v9inode->v_mutex);
327 if ((v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) &&
328 !v9inode->writeback_fid &&
329 ((flags & O_ACCMODE) != O_RDONLY)) {
331 * clone a fid and add it to writeback_fid
332 * we do it during open time instead of
333 * page dirty time via write_begin/page_mkwrite
334 * because we want write after unlink usecase
337 inode_fid = v9fs_writeback_fid(dentry);
338 if (IS_ERR(inode_fid)) {
339 err = PTR_ERR(inode_fid);
340 mutex_unlock(&v9inode->v_mutex);
341 goto err_clunk_old_fid;
343 v9inode->writeback_fid = (void *) inode_fid;
345 mutex_unlock(&v9inode->v_mutex);
346 /* Since we are opening a file, assign the open fid to the file */
347 err = finish_open(file, dentry, generic_file_open);
349 goto err_clunk_old_fid;
350 file->private_data = ofid;
351 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
352 v9fs_cache_inode_set_cookie(inode, file);
353 v9fs_open_fid_add(inode, ofid);
354 file->f_mode |= FMODE_CREATED;
356 v9fs_put_acl(dacl, pacl);
362 p9_client_clunk(fid);
365 p9_client_clunk(ofid);
370 * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory
371 * @mnt_userns: The user namespace of the mount
372 * @dir: inode that is being unlinked
373 * @dentry: dentry that is being unlinked
374 * @omode: mode for new directory
378 static int v9fs_vfs_mkdir_dotl(struct user_namespace *mnt_userns,
379 struct inode *dir, struct dentry *dentry,
383 struct v9fs_session_info *v9ses;
384 struct p9_fid *fid = NULL, *dfid = NULL;
386 const unsigned char *name;
390 struct posix_acl *dacl = NULL, *pacl = NULL;
392 p9_debug(P9_DEBUG_VFS, "name %pd\n", dentry);
394 v9ses = v9fs_inode2v9ses(dir);
397 if (dir->i_mode & S_ISGID)
400 dfid = v9fs_parent_fid(dentry);
403 p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
408 gid = v9fs_get_fsgid_for_create(dir);
410 /* Update mode based on ACL value */
411 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
413 p9_debug(P9_DEBUG_VFS, "Failed to get acl values in mkdir %d\n",
417 name = dentry->d_name.name;
418 err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid);
421 fid = p9_client_walk(dfid, 1, &name, 1);
424 p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
430 /* instantiate inode and assign the unopened fid to the dentry */
431 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
432 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
434 err = PTR_ERR(inode);
435 p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",
439 v9fs_fid_add(dentry, fid);
440 v9fs_set_create_acl(inode, fid, dacl, pacl);
441 d_instantiate(dentry, inode);
446 * Not in cached mode. No need to populate
447 * inode with stat. We need to get an inode
448 * so that we can set the acl with dentry
450 inode = v9fs_get_inode(dir->i_sb, mode, 0);
452 err = PTR_ERR(inode);
455 v9fs_set_create_acl(inode, fid, dacl, pacl);
456 d_instantiate(dentry, inode);
459 v9fs_invalidate_inode_attr(dir);
462 p9_client_clunk(fid);
463 v9fs_put_acl(dacl, pacl);
464 p9_client_clunk(dfid);
469 v9fs_vfs_getattr_dotl(struct user_namespace *mnt_userns,
470 const struct path *path, struct kstat *stat,
471 u32 request_mask, unsigned int flags)
473 struct dentry *dentry = path->dentry;
474 struct v9fs_session_info *v9ses;
476 struct p9_stat_dotl *st;
478 p9_debug(P9_DEBUG_VFS, "dentry: %p\n", dentry);
479 v9ses = v9fs_dentry2v9ses(dentry);
480 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
481 generic_fillattr(&init_user_ns, d_inode(dentry), stat);
484 fid = v9fs_fid_lookup(dentry);
488 /* Ask for all the fields in stat structure. Server will return
489 * whatever it supports
492 st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
493 p9_client_clunk(fid);
497 v9fs_stat2inode_dotl(st, d_inode(dentry), 0);
498 generic_fillattr(&init_user_ns, d_inode(dentry), stat);
499 /* Change block size to what the server returned */
500 stat->blksize = st->st_blksize;
509 #define P9_ATTR_MODE (1 << 0)
510 #define P9_ATTR_UID (1 << 1)
511 #define P9_ATTR_GID (1 << 2)
512 #define P9_ATTR_SIZE (1 << 3)
513 #define P9_ATTR_ATIME (1 << 4)
514 #define P9_ATTR_MTIME (1 << 5)
515 #define P9_ATTR_CTIME (1 << 6)
516 #define P9_ATTR_ATIME_SET (1 << 7)
517 #define P9_ATTR_MTIME_SET (1 << 8)
519 struct dotl_iattr_map {
524 static int v9fs_mapped_iattr_valid(int iattr_valid)
527 int p9_iattr_valid = 0;
528 struct dotl_iattr_map dotl_iattr_map[] = {
529 { ATTR_MODE, P9_ATTR_MODE },
530 { ATTR_UID, P9_ATTR_UID },
531 { ATTR_GID, P9_ATTR_GID },
532 { ATTR_SIZE, P9_ATTR_SIZE },
533 { ATTR_ATIME, P9_ATTR_ATIME },
534 { ATTR_MTIME, P9_ATTR_MTIME },
535 { ATTR_CTIME, P9_ATTR_CTIME },
536 { ATTR_ATIME_SET, P9_ATTR_ATIME_SET },
537 { ATTR_MTIME_SET, P9_ATTR_MTIME_SET },
539 for (i = 0; i < ARRAY_SIZE(dotl_iattr_map); i++) {
540 if (iattr_valid & dotl_iattr_map[i].iattr_valid)
541 p9_iattr_valid |= dotl_iattr_map[i].p9_iattr_valid;
543 return p9_iattr_valid;
547 * v9fs_vfs_setattr_dotl - set file metadata
548 * @mnt_userns: The user namespace of the mount
549 * @dentry: file whose metadata to set
550 * @iattr: metadata assignment structure
554 int v9fs_vfs_setattr_dotl(struct user_namespace *mnt_userns,
555 struct dentry *dentry, struct iattr *iattr)
557 int retval, use_dentry = 0;
558 struct p9_fid *fid = NULL;
559 struct p9_iattr_dotl p9attr = {
563 struct inode *inode = d_inode(dentry);
565 p9_debug(P9_DEBUG_VFS, "\n");
567 retval = setattr_prepare(&init_user_ns, dentry, iattr);
571 p9attr.valid = v9fs_mapped_iattr_valid(iattr->ia_valid);
572 if (iattr->ia_valid & ATTR_MODE)
573 p9attr.mode = iattr->ia_mode;
574 if (iattr->ia_valid & ATTR_UID)
575 p9attr.uid = iattr->ia_uid;
576 if (iattr->ia_valid & ATTR_GID)
577 p9attr.gid = iattr->ia_gid;
578 if (iattr->ia_valid & ATTR_SIZE)
579 p9attr.size = iattr->ia_size;
580 if (iattr->ia_valid & ATTR_ATIME_SET) {
581 p9attr.atime_sec = iattr->ia_atime.tv_sec;
582 p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
584 if (iattr->ia_valid & ATTR_MTIME_SET) {
585 p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
586 p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
589 if (iattr->ia_valid & ATTR_FILE) {
590 fid = iattr->ia_file->private_data;
594 fid = v9fs_fid_lookup(dentry);
600 /* Write all dirty data */
601 if (S_ISREG(inode->i_mode))
602 filemap_write_and_wait(inode->i_mapping);
604 retval = p9_client_setattr(fid, &p9attr);
607 p9_client_clunk(fid);
611 if ((iattr->ia_valid & ATTR_SIZE) &&
612 iattr->ia_size != i_size_read(inode))
613 truncate_setsize(inode, iattr->ia_size);
615 v9fs_invalidate_inode_attr(inode);
616 setattr_copy(&init_user_ns, inode, iattr);
617 mark_inode_dirty(inode);
618 if (iattr->ia_valid & ATTR_MODE) {
619 /* We also want to update ACL when we update mode bits */
620 retval = v9fs_acl_chmod(inode, fid);
623 p9_client_clunk(fid);
628 p9_client_clunk(fid);
634 * v9fs_stat2inode_dotl - populate an inode structure with stat info
635 * @stat: stat structure
636 * @inode: inode to populate
637 * @flags: ctrl flags (e.g. V9FS_STAT2INODE_KEEP_ISIZE)
642 v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode,
646 struct v9fs_inode *v9inode = V9FS_I(inode);
648 if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) {
649 inode->i_atime.tv_sec = stat->st_atime_sec;
650 inode->i_atime.tv_nsec = stat->st_atime_nsec;
651 inode->i_mtime.tv_sec = stat->st_mtime_sec;
652 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
653 inode->i_ctime.tv_sec = stat->st_ctime_sec;
654 inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
655 inode->i_uid = stat->st_uid;
656 inode->i_gid = stat->st_gid;
657 set_nlink(inode, stat->st_nlink);
659 mode = stat->st_mode & S_IALLUGO;
660 mode |= inode->i_mode & ~S_IALLUGO;
661 inode->i_mode = mode;
663 if (!(flags & V9FS_STAT2INODE_KEEP_ISIZE))
664 v9fs_i_size_write(inode, stat->st_size);
665 inode->i_blocks = stat->st_blocks;
667 if (stat->st_result_mask & P9_STATS_ATIME) {
668 inode->i_atime.tv_sec = stat->st_atime_sec;
669 inode->i_atime.tv_nsec = stat->st_atime_nsec;
671 if (stat->st_result_mask & P9_STATS_MTIME) {
672 inode->i_mtime.tv_sec = stat->st_mtime_sec;
673 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
675 if (stat->st_result_mask & P9_STATS_CTIME) {
676 inode->i_ctime.tv_sec = stat->st_ctime_sec;
677 inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
679 if (stat->st_result_mask & P9_STATS_UID)
680 inode->i_uid = stat->st_uid;
681 if (stat->st_result_mask & P9_STATS_GID)
682 inode->i_gid = stat->st_gid;
683 if (stat->st_result_mask & P9_STATS_NLINK)
684 set_nlink(inode, stat->st_nlink);
685 if (stat->st_result_mask & P9_STATS_MODE) {
686 mode = stat->st_mode & S_IALLUGO;
687 mode |= inode->i_mode & ~S_IALLUGO;
688 inode->i_mode = mode;
690 if (!(flags & V9FS_STAT2INODE_KEEP_ISIZE) &&
691 stat->st_result_mask & P9_STATS_SIZE)
692 v9fs_i_size_write(inode, stat->st_size);
693 if (stat->st_result_mask & P9_STATS_BLOCKS)
694 inode->i_blocks = stat->st_blocks;
696 if (stat->st_result_mask & P9_STATS_GEN)
697 inode->i_generation = stat->st_gen;
699 /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION
700 * because the inode structure does not have fields for them.
702 v9inode->cache_validity &= ~V9FS_INO_INVALID_ATTR;
706 v9fs_vfs_symlink_dotl(struct user_namespace *mnt_userns, struct inode *dir,
707 struct dentry *dentry, const char *symname)
711 const unsigned char *name;
715 struct p9_fid *fid = NULL;
716 struct v9fs_session_info *v9ses;
718 name = dentry->d_name.name;
719 p9_debug(P9_DEBUG_VFS, "%lu,%s,%s\n", dir->i_ino, name, symname);
720 v9ses = v9fs_inode2v9ses(dir);
722 dfid = v9fs_parent_fid(dentry);
725 p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
729 gid = v9fs_get_fsgid_for_create(dir);
731 /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */
732 err = p9_client_symlink(dfid, name, symname, gid, &qid);
735 p9_debug(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err);
739 v9fs_invalidate_inode_attr(dir);
740 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
741 /* Now walk from the parent so we can get an unopened fid. */
742 fid = p9_client_walk(dfid, 1, &name, 1);
745 p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
751 /* instantiate inode and assign the unopened fid to dentry */
752 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
754 err = PTR_ERR(inode);
755 p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",
759 v9fs_fid_add(dentry, fid);
760 d_instantiate(dentry, inode);
764 /* Not in cached mode. No need to populate inode with stat */
765 inode = v9fs_get_inode(dir->i_sb, S_IFLNK, 0);
767 err = PTR_ERR(inode);
770 d_instantiate(dentry, inode);
775 p9_client_clunk(fid);
777 p9_client_clunk(dfid);
782 * v9fs_vfs_link_dotl - create a hardlink for dotl
783 * @old_dentry: dentry for file to link to
784 * @dir: inode destination for new link
785 * @dentry: dentry for link
790 v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
791 struct dentry *dentry)
794 struct p9_fid *dfid, *oldfid;
795 struct v9fs_session_info *v9ses;
797 p9_debug(P9_DEBUG_VFS, "dir ino: %lu, old_name: %pd, new_name: %pd\n",
798 dir->i_ino, old_dentry, dentry);
800 v9ses = v9fs_inode2v9ses(dir);
801 dfid = v9fs_parent_fid(dentry);
803 return PTR_ERR(dfid);
805 oldfid = v9fs_fid_lookup(old_dentry);
806 if (IS_ERR(oldfid)) {
807 p9_client_clunk(dfid);
808 return PTR_ERR(oldfid);
811 err = p9_client_link(dfid, oldfid, dentry->d_name.name);
813 p9_client_clunk(dfid);
814 p9_client_clunk(oldfid);
816 p9_debug(P9_DEBUG_VFS, "p9_client_link failed %d\n", err);
820 v9fs_invalidate_inode_attr(dir);
821 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
822 /* Get the latest stat info from server. */
825 fid = v9fs_fid_lookup(old_dentry);
829 v9fs_refresh_inode_dotl(fid, d_inode(old_dentry));
830 p9_client_clunk(fid);
832 ihold(d_inode(old_dentry));
833 d_instantiate(dentry, d_inode(old_dentry));
839 * v9fs_vfs_mknod_dotl - create a special file
840 * @mnt_userns: The user namespace of the mount
841 * @dir: inode destination for new link
842 * @dentry: dentry for file
843 * @omode: mode for creation
844 * @rdev: device associated with special file
848 v9fs_vfs_mknod_dotl(struct user_namespace *mnt_userns, struct inode *dir,
849 struct dentry *dentry, umode_t omode, dev_t rdev)
853 const unsigned char *name;
855 struct v9fs_session_info *v9ses;
856 struct p9_fid *fid = NULL, *dfid = NULL;
859 struct posix_acl *dacl = NULL, *pacl = NULL;
861 p9_debug(P9_DEBUG_VFS, " %lu,%pd mode: %x MAJOR: %u MINOR: %u\n",
862 dir->i_ino, dentry, omode,
863 MAJOR(rdev), MINOR(rdev));
865 v9ses = v9fs_inode2v9ses(dir);
866 dfid = v9fs_parent_fid(dentry);
869 p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
874 gid = v9fs_get_fsgid_for_create(dir);
876 /* Update mode based on ACL value */
877 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
879 p9_debug(P9_DEBUG_VFS, "Failed to get acl values in mknod %d\n",
883 name = dentry->d_name.name;
885 err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid);
889 v9fs_invalidate_inode_attr(dir);
890 fid = p9_client_walk(dfid, 1, &name, 1);
893 p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
899 /* instantiate inode and assign the unopened fid to the dentry */
900 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
901 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
903 err = PTR_ERR(inode);
904 p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",
908 v9fs_set_create_acl(inode, fid, dacl, pacl);
909 v9fs_fid_add(dentry, fid);
910 d_instantiate(dentry, inode);
915 * Not in cached mode. No need to populate inode with stat.
916 * socket syscall returns a fd, so we need instantiate
918 inode = v9fs_get_inode(dir->i_sb, mode, rdev);
920 err = PTR_ERR(inode);
923 v9fs_set_create_acl(inode, fid, dacl, pacl);
924 d_instantiate(dentry, inode);
928 p9_client_clunk(fid);
929 v9fs_put_acl(dacl, pacl);
930 p9_client_clunk(dfid);
936 * v9fs_vfs_get_link_dotl - follow a symlink path
937 * @dentry: dentry for symlink
938 * @inode: inode for symlink
939 * @done: destructor for return value
943 v9fs_vfs_get_link_dotl(struct dentry *dentry,
945 struct delayed_call *done)
952 return ERR_PTR(-ECHILD);
954 p9_debug(P9_DEBUG_VFS, "%pd\n", dentry);
956 fid = v9fs_fid_lookup(dentry);
958 return ERR_CAST(fid);
959 retval = p9_client_readlink(fid, &target);
960 p9_client_clunk(fid);
962 return ERR_PTR(retval);
963 set_delayed_call(done, kfree_link, target);
967 int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode)
969 struct p9_stat_dotl *st;
970 struct v9fs_session_info *v9ses;
973 v9ses = v9fs_inode2v9ses(inode);
974 st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
978 * Don't update inode if the file type is different
980 if (inode_wrong_type(inode, st->st_mode))
984 * We don't want to refresh inode->i_size,
985 * because we may have cached data
987 flags = (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) ?
988 V9FS_STAT2INODE_KEEP_ISIZE : 0;
989 v9fs_stat2inode_dotl(st, inode, flags);
995 const struct inode_operations v9fs_dir_inode_operations_dotl = {
996 .create = v9fs_vfs_create_dotl,
997 .atomic_open = v9fs_vfs_atomic_open_dotl,
998 .lookup = v9fs_vfs_lookup,
999 .link = v9fs_vfs_link_dotl,
1000 .symlink = v9fs_vfs_symlink_dotl,
1001 .unlink = v9fs_vfs_unlink,
1002 .mkdir = v9fs_vfs_mkdir_dotl,
1003 .rmdir = v9fs_vfs_rmdir,
1004 .mknod = v9fs_vfs_mknod_dotl,
1005 .rename = v9fs_vfs_rename,
1006 .getattr = v9fs_vfs_getattr_dotl,
1007 .setattr = v9fs_vfs_setattr_dotl,
1008 .listxattr = v9fs_listxattr,
1009 .get_acl = v9fs_iop_get_acl,
1012 const struct inode_operations v9fs_file_inode_operations_dotl = {
1013 .getattr = v9fs_vfs_getattr_dotl,
1014 .setattr = v9fs_vfs_setattr_dotl,
1015 .listxattr = v9fs_listxattr,
1016 .get_acl = v9fs_iop_get_acl,
1019 const struct inode_operations v9fs_symlink_inode_operations_dotl = {
1020 .get_link = v9fs_vfs_get_link_dotl,
1021 .getattr = v9fs_vfs_getattr_dotl,
1022 .setattr = v9fs_vfs_setattr_dotl,
1023 .listxattr = v9fs_listxattr,