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 *, void *);
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 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%hx\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);
282 gid = v9fs_get_fsgid_for_create(dir);
285 /* Update mode based on ACL value */
286 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
288 p9_debug(P9_DEBUG_VFS, "Failed to get acl values in creat %d\n",
292 err = p9_client_create_dotl(ofid, name, v9fs_open_to_dotl_flags(flags),
295 p9_debug(P9_DEBUG_VFS, "p9_client_open_dotl failed in creat %d\n",
299 v9fs_invalidate_inode_attr(dir);
301 /* instantiate inode and assign the unopened fid to the dentry */
302 fid = p9_client_walk(dfid, 1, &name, 1);
303 p9_client_clunk(dfid);
306 p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
310 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
312 err = PTR_ERR(inode);
313 p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n", err);
316 /* Now set the ACL based on the default value */
317 v9fs_set_create_acl(inode, fid, dacl, pacl);
319 v9fs_fid_add(dentry, fid);
320 d_instantiate(dentry, inode);
322 v9inode = V9FS_I(inode);
323 mutex_lock(&v9inode->v_mutex);
324 if ((v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) &&
325 !v9inode->writeback_fid &&
326 ((flags & O_ACCMODE) != O_RDONLY)) {
328 * clone a fid and add it to writeback_fid
329 * we do it during open time instead of
330 * page dirty time via write_begin/page_mkwrite
331 * because we want write after unlink usecase
334 inode_fid = v9fs_writeback_fid(dentry);
335 if (IS_ERR(inode_fid)) {
336 err = PTR_ERR(inode_fid);
337 mutex_unlock(&v9inode->v_mutex);
338 goto err_clunk_old_fid;
340 v9inode->writeback_fid = (void *) inode_fid;
342 mutex_unlock(&v9inode->v_mutex);
343 /* Since we are opening a file, assign the open fid to the file */
344 err = finish_open(file, dentry, generic_file_open);
346 goto err_clunk_old_fid;
347 file->private_data = ofid;
348 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
349 v9fs_cache_inode_set_cookie(inode, file);
350 v9fs_open_fid_add(inode, ofid);
351 file->f_mode |= FMODE_CREATED;
353 v9fs_put_acl(dacl, pacl);
359 p9_client_clunk(fid);
362 p9_client_clunk(ofid);
367 * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory
368 * @mnt_userns: The user namespace of the mount
369 * @dir: inode that is being unlinked
370 * @dentry: dentry that is being unlinked
371 * @omode: mode for new directory
375 static int v9fs_vfs_mkdir_dotl(struct user_namespace *mnt_userns,
376 struct inode *dir, struct dentry *dentry,
380 struct v9fs_session_info *v9ses;
381 struct p9_fid *fid = NULL, *dfid = NULL;
383 const unsigned char *name;
387 struct posix_acl *dacl = NULL, *pacl = NULL;
389 p9_debug(P9_DEBUG_VFS, "name %pd\n", dentry);
391 v9ses = v9fs_inode2v9ses(dir);
394 if (dir->i_mode & S_ISGID)
397 dfid = v9fs_parent_fid(dentry);
400 p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
405 gid = v9fs_get_fsgid_for_create(dir);
407 /* Update mode based on ACL value */
408 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
410 p9_debug(P9_DEBUG_VFS, "Failed to get acl values in mkdir %d\n",
414 name = dentry->d_name.name;
415 err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid);
418 fid = p9_client_walk(dfid, 1, &name, 1);
421 p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
427 /* instantiate inode and assign the unopened fid to the dentry */
428 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
429 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
431 err = PTR_ERR(inode);
432 p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",
436 v9fs_fid_add(dentry, fid);
437 v9fs_set_create_acl(inode, fid, dacl, pacl);
438 d_instantiate(dentry, inode);
443 * Not in cached mode. No need to populate
444 * inode with stat. We need to get an inode
445 * so that we can set the acl with dentry
447 inode = v9fs_get_inode(dir->i_sb, mode, 0);
449 err = PTR_ERR(inode);
452 v9fs_set_create_acl(inode, fid, dacl, pacl);
453 d_instantiate(dentry, inode);
456 v9fs_invalidate_inode_attr(dir);
459 p9_client_clunk(fid);
460 v9fs_put_acl(dacl, pacl);
461 p9_client_clunk(dfid);
466 v9fs_vfs_getattr_dotl(struct user_namespace *mnt_userns,
467 const struct path *path, struct kstat *stat,
468 u32 request_mask, unsigned int flags)
470 struct dentry *dentry = path->dentry;
471 struct v9fs_session_info *v9ses;
473 struct p9_stat_dotl *st;
475 p9_debug(P9_DEBUG_VFS, "dentry: %p\n", dentry);
476 v9ses = v9fs_dentry2v9ses(dentry);
477 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
478 generic_fillattr(&init_user_ns, d_inode(dentry), stat);
481 fid = v9fs_fid_lookup(dentry);
485 /* Ask for all the fields in stat structure. Server will return
486 * whatever it supports
489 st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
490 p9_client_clunk(fid);
494 v9fs_stat2inode_dotl(st, d_inode(dentry), 0);
495 generic_fillattr(&init_user_ns, d_inode(dentry), stat);
496 /* Change block size to what the server returned */
497 stat->blksize = st->st_blksize;
506 #define P9_ATTR_MODE (1 << 0)
507 #define P9_ATTR_UID (1 << 1)
508 #define P9_ATTR_GID (1 << 2)
509 #define P9_ATTR_SIZE (1 << 3)
510 #define P9_ATTR_ATIME (1 << 4)
511 #define P9_ATTR_MTIME (1 << 5)
512 #define P9_ATTR_CTIME (1 << 6)
513 #define P9_ATTR_ATIME_SET (1 << 7)
514 #define P9_ATTR_MTIME_SET (1 << 8)
516 struct dotl_iattr_map {
521 static int v9fs_mapped_iattr_valid(int iattr_valid)
524 int p9_iattr_valid = 0;
525 struct dotl_iattr_map dotl_iattr_map[] = {
526 { ATTR_MODE, P9_ATTR_MODE },
527 { ATTR_UID, P9_ATTR_UID },
528 { ATTR_GID, P9_ATTR_GID },
529 { ATTR_SIZE, P9_ATTR_SIZE },
530 { ATTR_ATIME, P9_ATTR_ATIME },
531 { ATTR_MTIME, P9_ATTR_MTIME },
532 { ATTR_CTIME, P9_ATTR_CTIME },
533 { ATTR_ATIME_SET, P9_ATTR_ATIME_SET },
534 { ATTR_MTIME_SET, P9_ATTR_MTIME_SET },
536 for (i = 0; i < ARRAY_SIZE(dotl_iattr_map); i++) {
537 if (iattr_valid & dotl_iattr_map[i].iattr_valid)
538 p9_iattr_valid |= dotl_iattr_map[i].p9_iattr_valid;
540 return p9_iattr_valid;
544 * v9fs_vfs_setattr_dotl - set file metadata
545 * @mnt_userns: The user namespace of the mount
546 * @dentry: file whose metadata to set
547 * @iattr: metadata assignment structure
551 int v9fs_vfs_setattr_dotl(struct user_namespace *mnt_userns,
552 struct dentry *dentry, struct iattr *iattr)
554 int retval, use_dentry = 0;
555 struct p9_fid *fid = NULL;
556 struct p9_iattr_dotl p9attr;
557 struct inode *inode = d_inode(dentry);
559 p9_debug(P9_DEBUG_VFS, "\n");
561 retval = setattr_prepare(&init_user_ns, dentry, iattr);
565 p9attr.valid = v9fs_mapped_iattr_valid(iattr->ia_valid);
566 p9attr.mode = iattr->ia_mode;
567 p9attr.uid = iattr->ia_uid;
568 p9attr.gid = iattr->ia_gid;
569 p9attr.size = iattr->ia_size;
570 p9attr.atime_sec = iattr->ia_atime.tv_sec;
571 p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
572 p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
573 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);
593 p9_client_clunk(fid);
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);
609 p9_client_clunk(fid);
614 p9_client_clunk(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",
737 /* instantiate inode and assign the unopened fid to dentry */
738 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
740 err = PTR_ERR(inode);
741 p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",
745 v9fs_fid_add(dentry, fid);
746 d_instantiate(dentry, inode);
750 /* Not in cached mode. No need to populate inode with stat */
751 inode = v9fs_get_inode(dir->i_sb, S_IFLNK, 0);
753 err = PTR_ERR(inode);
756 d_instantiate(dentry, inode);
761 p9_client_clunk(fid);
763 p9_client_clunk(dfid);
768 * v9fs_vfs_link_dotl - create a hardlink for dotl
769 * @old_dentry: dentry for file to link to
770 * @dir: inode destination for new link
771 * @dentry: dentry for link
776 v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
777 struct dentry *dentry)
780 struct p9_fid *dfid, *oldfid;
781 struct v9fs_session_info *v9ses;
783 p9_debug(P9_DEBUG_VFS, "dir ino: %lu, old_name: %pd, new_name: %pd\n",
784 dir->i_ino, old_dentry, dentry);
786 v9ses = v9fs_inode2v9ses(dir);
787 dfid = v9fs_parent_fid(dentry);
789 return PTR_ERR(dfid);
791 oldfid = v9fs_fid_lookup(old_dentry);
792 if (IS_ERR(oldfid)) {
793 p9_client_clunk(dfid);
794 return PTR_ERR(oldfid);
797 err = p9_client_link(dfid, oldfid, dentry->d_name.name);
799 p9_client_clunk(dfid);
800 p9_client_clunk(oldfid);
802 p9_debug(P9_DEBUG_VFS, "p9_client_link failed %d\n", err);
806 v9fs_invalidate_inode_attr(dir);
807 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
808 /* Get the latest stat info from server. */
810 fid = v9fs_fid_lookup(old_dentry);
814 v9fs_refresh_inode_dotl(fid, d_inode(old_dentry));
815 p9_client_clunk(fid);
817 ihold(d_inode(old_dentry));
818 d_instantiate(dentry, d_inode(old_dentry));
824 * v9fs_vfs_mknod_dotl - create a special file
825 * @mnt_userns: The user namespace of the mount
826 * @dir: inode destination for new link
827 * @dentry: dentry for file
828 * @omode: mode for creation
829 * @rdev: device associated with special file
833 v9fs_vfs_mknod_dotl(struct user_namespace *mnt_userns, struct inode *dir,
834 struct dentry *dentry, umode_t omode, dev_t rdev)
838 const unsigned char *name;
840 struct v9fs_session_info *v9ses;
841 struct p9_fid *fid = NULL, *dfid = NULL;
844 struct posix_acl *dacl = NULL, *pacl = NULL;
846 p9_debug(P9_DEBUG_VFS, " %lu,%pd mode: %hx MAJOR: %u MINOR: %u\n",
847 dir->i_ino, dentry, omode,
848 MAJOR(rdev), MINOR(rdev));
850 v9ses = v9fs_inode2v9ses(dir);
851 dfid = v9fs_parent_fid(dentry);
854 p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
859 gid = v9fs_get_fsgid_for_create(dir);
861 /* Update mode based on ACL value */
862 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
864 p9_debug(P9_DEBUG_VFS, "Failed to get acl values in mknod %d\n",
868 name = dentry->d_name.name;
870 err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid);
874 v9fs_invalidate_inode_attr(dir);
875 fid = p9_client_walk(dfid, 1, &name, 1);
878 p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
884 /* instantiate inode and assign the unopened fid to the dentry */
885 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
886 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
888 err = PTR_ERR(inode);
889 p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",
893 v9fs_set_create_acl(inode, fid, dacl, pacl);
894 v9fs_fid_add(dentry, fid);
895 d_instantiate(dentry, inode);
900 * Not in cached mode. No need to populate inode with stat.
901 * socket syscall returns a fd, so we need instantiate
903 inode = v9fs_get_inode(dir->i_sb, mode, rdev);
905 err = PTR_ERR(inode);
908 v9fs_set_create_acl(inode, fid, dacl, pacl);
909 d_instantiate(dentry, inode);
913 p9_client_clunk(fid);
914 v9fs_put_acl(dacl, pacl);
915 p9_client_clunk(dfid);
921 * v9fs_vfs_get_link_dotl - follow a symlink path
922 * @dentry: dentry for symlink
923 * @inode: inode for symlink
924 * @done: destructor for return value
928 v9fs_vfs_get_link_dotl(struct dentry *dentry,
930 struct delayed_call *done)
937 return ERR_PTR(-ECHILD);
939 p9_debug(P9_DEBUG_VFS, "%pd\n", dentry);
941 fid = v9fs_fid_lookup(dentry);
943 return ERR_CAST(fid);
944 retval = p9_client_readlink(fid, &target);
945 p9_client_clunk(fid);
947 return ERR_PTR(retval);
948 set_delayed_call(done, kfree_link, target);
952 int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode)
954 struct p9_stat_dotl *st;
955 struct v9fs_session_info *v9ses;
958 v9ses = v9fs_inode2v9ses(inode);
959 st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
963 * Don't update inode if the file type is different
965 if (inode_wrong_type(inode, st->st_mode))
969 * We don't want to refresh inode->i_size,
970 * because we may have cached data
972 flags = (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) ?
973 V9FS_STAT2INODE_KEEP_ISIZE : 0;
974 v9fs_stat2inode_dotl(st, inode, flags);
980 const struct inode_operations v9fs_dir_inode_operations_dotl = {
981 .create = v9fs_vfs_create_dotl,
982 .atomic_open = v9fs_vfs_atomic_open_dotl,
983 .lookup = v9fs_vfs_lookup,
984 .link = v9fs_vfs_link_dotl,
985 .symlink = v9fs_vfs_symlink_dotl,
986 .unlink = v9fs_vfs_unlink,
987 .mkdir = v9fs_vfs_mkdir_dotl,
988 .rmdir = v9fs_vfs_rmdir,
989 .mknod = v9fs_vfs_mknod_dotl,
990 .rename = v9fs_vfs_rename,
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_file_inode_operations_dotl = {
998 .getattr = v9fs_vfs_getattr_dotl,
999 .setattr = v9fs_vfs_setattr_dotl,
1000 .listxattr = v9fs_listxattr,
1001 .get_acl = v9fs_iop_get_acl,
1004 const struct inode_operations v9fs_symlink_inode_operations_dotl = {
1005 .get_link = v9fs_vfs_get_link_dotl,
1006 .getattr = v9fs_vfs_getattr_dotl,
1007 .setattr = v9fs_vfs_setattr_dotl,
1008 .listxattr = v9fs_listxattr,