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/namei.h>
17 #include <linux/sched.h>
18 #include <linux/slab.h>
19 #include <linux/xattr.h>
20 #include <linux/posix_acl.h>
21 #include <net/9p/9p.h>
22 #include <net/9p/client.h>
32 v9fs_vfs_mknod_dotl(struct mnt_idmap *idmap, struct inode *dir,
33 struct dentry *dentry, umode_t omode, dev_t rdev);
36 * v9fs_get_fsgid_for_create - Helper function to get the gid for a new object
37 * @dir_inode: The directory inode
39 * Helper function to get the gid for creating a
40 * new file system object. This checks the S_ISGID to determine the owning
41 * group of the new file system object.
44 static kgid_t v9fs_get_fsgid_for_create(struct inode *dir_inode)
46 BUG_ON(dir_inode == NULL);
48 if (dir_inode->i_mode & S_ISGID) {
49 /* set_gid bit is set.*/
50 return dir_inode->i_gid;
52 return current_fsgid();
55 static int v9fs_test_inode_dotl(struct inode *inode, void *data)
57 struct v9fs_inode *v9inode = V9FS_I(inode);
58 struct p9_stat_dotl *st = (struct p9_stat_dotl *)data;
60 /* don't match inode of different type */
61 if (inode_wrong_type(inode, st->st_mode))
64 if (inode->i_generation != st->st_gen)
67 /* compare qid details */
68 if (memcmp(&v9inode->qid.version,
69 &st->qid.version, sizeof(v9inode->qid.version)))
72 if (v9inode->qid.type != st->qid.type)
75 if (v9inode->qid.path != st->qid.path)
80 /* Always get a new inode */
81 static int v9fs_test_new_inode_dotl(struct inode *inode, void *data)
86 static int v9fs_set_inode_dotl(struct inode *inode, void *data)
88 struct v9fs_inode *v9inode = V9FS_I(inode);
89 struct p9_stat_dotl *st = (struct p9_stat_dotl *)data;
91 memcpy(&v9inode->qid, &st->qid, sizeof(st->qid));
92 inode->i_generation = st->st_gen;
96 static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,
99 struct p9_stat_dotl *st,
105 struct v9fs_session_info *v9ses = sb->s_fs_info;
106 int (*test)(struct inode *inode, void *data);
109 test = v9fs_test_new_inode_dotl;
111 test = v9fs_test_inode_dotl;
113 i_ino = v9fs_qid2ino(qid);
114 inode = iget5_locked(sb, i_ino, test, v9fs_set_inode_dotl, st);
116 return ERR_PTR(-ENOMEM);
117 if (!(inode->i_state & I_NEW))
120 * initialize the inode with the stat info
121 * FIXME!! we may need support for stale inodes
124 inode->i_ino = i_ino;
125 retval = v9fs_init_inode(v9ses, inode,
126 st->st_mode, new_decode_dev(st->st_rdev));
130 v9fs_stat2inode_dotl(st, inode, 0);
131 v9fs_cache_inode_get_cookie(inode);
132 retval = v9fs_get_acl(inode, fid);
136 unlock_new_inode(inode);
140 return ERR_PTR(retval);
145 v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid,
146 struct super_block *sb, int new)
148 struct p9_stat_dotl *st;
149 struct inode *inode = NULL;
151 st = p9_client_getattr_dotl(fid, P9_STATS_BASIC | P9_STATS_GEN);
155 inode = v9fs_qid_iget_dotl(sb, &st->qid, fid, st, new);
160 struct dotl_openflag_map {
165 static int v9fs_mapped_dotl_flags(int flags)
169 struct dotl_openflag_map dotl_oflag_map[] = {
170 { O_CREAT, P9_DOTL_CREATE },
171 { O_EXCL, P9_DOTL_EXCL },
172 { O_NOCTTY, P9_DOTL_NOCTTY },
173 { O_APPEND, P9_DOTL_APPEND },
174 { O_NONBLOCK, P9_DOTL_NONBLOCK },
175 { O_DSYNC, P9_DOTL_DSYNC },
176 { FASYNC, P9_DOTL_FASYNC },
177 { O_DIRECT, P9_DOTL_DIRECT },
178 { O_LARGEFILE, P9_DOTL_LARGEFILE },
179 { O_DIRECTORY, P9_DOTL_DIRECTORY },
180 { O_NOFOLLOW, P9_DOTL_NOFOLLOW },
181 { O_NOATIME, P9_DOTL_NOATIME },
182 { O_CLOEXEC, P9_DOTL_CLOEXEC },
183 { O_SYNC, P9_DOTL_SYNC},
185 for (i = 0; i < ARRAY_SIZE(dotl_oflag_map); i++) {
186 if (flags & dotl_oflag_map[i].open_flag)
187 rflags |= dotl_oflag_map[i].dotl_flag;
193 * v9fs_open_to_dotl_flags- convert Linux specific open flags to
195 * @flags: flags to convert
197 int v9fs_open_to_dotl_flags(int flags)
202 * We have same bits for P9_DOTL_READONLY, P9_DOTL_WRONLY
203 * and P9_DOTL_NOACCESS
205 rflags |= flags & O_ACCMODE;
206 rflags |= v9fs_mapped_dotl_flags(flags);
212 * v9fs_vfs_create_dotl - VFS hook to create files for 9P2000.L protocol.
213 * @idmap: The user namespace of the mount
214 * @dir: directory inode that is being created
215 * @dentry: dentry that is being deleted
216 * @omode: create permissions
217 * @excl: True if the file must not yet exist
221 v9fs_vfs_create_dotl(struct mnt_idmap *idmap, struct inode *dir,
222 struct dentry *dentry, umode_t omode, bool excl)
224 return v9fs_vfs_mknod_dotl(idmap, dir, dentry, omode, 0);
228 v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,
229 struct file *file, unsigned int flags, umode_t omode)
234 int p9_omode = v9fs_open_to_dotl_flags(flags);
235 const unsigned char *name = NULL;
238 struct p9_fid *fid = NULL;
239 struct p9_fid *dfid = NULL, *ofid = NULL;
240 struct v9fs_session_info *v9ses;
241 struct posix_acl *pacl = NULL, *dacl = NULL;
242 struct dentry *res = NULL;
244 if (d_in_lookup(dentry)) {
245 res = v9fs_vfs_lookup(dir, dentry, 0);
254 if (!(flags & O_CREAT) || d_really_is_positive(dentry))
255 return finish_no_open(file, res);
257 v9ses = v9fs_inode2v9ses(dir);
259 name = dentry->d_name.name;
260 p9_debug(P9_DEBUG_VFS, "name:%s flags:0x%x mode:0x%x\n",
263 dfid = v9fs_parent_fid(dentry);
266 p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
270 /* clone a fid to use for creation */
271 ofid = clone_fid(dfid);
274 p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
278 gid = v9fs_get_fsgid_for_create(dir);
281 /* Update mode based on ACL value */
282 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
284 p9_debug(P9_DEBUG_VFS, "Failed to get acl values in create %d\n",
289 if ((v9ses->cache & CACHE_WRITEBACK) && (p9_omode & P9_OWRITE)) {
290 p9_omode = (p9_omode & ~P9_OWRITE) | P9_ORDWR;
291 p9_debug(P9_DEBUG_CACHE,
292 "write-only file with writeback enabled, creating w/ O_RDWR\n");
294 err = p9_client_create_dotl(ofid, name, p9_omode, mode, gid, &qid);
296 p9_debug(P9_DEBUG_VFS, "p9_client_open_dotl failed in create %d\n",
300 v9fs_invalidate_inode_attr(dir);
302 /* instantiate inode and assign the unopened fid to the dentry */
303 fid = p9_client_walk(dfid, 1, &name, 1);
306 p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
309 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
311 err = PTR_ERR(inode);
312 p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n", err);
315 /* Now set the ACL based on the default value */
316 v9fs_set_create_acl(inode, fid, dacl, pacl);
318 v9fs_fid_add(dentry, &fid);
319 d_instantiate(dentry, inode);
321 /* Since we are opening a file, assign the open fid to the file */
322 err = finish_open(file, dentry, generic_file_open);
325 file->private_data = ofid;
326 #ifdef CONFIG_9P_FSCACHE
327 if (v9ses->cache & CACHE_FSCACHE) {
328 struct v9fs_inode *v9inode = V9FS_I(inode);
329 fscache_use_cookie(v9fs_inode_cookie(v9inode),
330 file->f_mode & FMODE_WRITE);
333 v9fs_fid_add_modes(ofid, v9ses->flags, v9ses->cache, flags);
334 v9fs_open_fid_add(inode, &ofid);
335 file->f_mode |= FMODE_CREATED;
340 v9fs_put_acl(dacl, pacl);
346 * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory
347 * @idmap: The idmap of the mount
348 * @dir: inode that is being unlinked
349 * @dentry: dentry that is being unlinked
350 * @omode: mode for new directory
354 static int v9fs_vfs_mkdir_dotl(struct mnt_idmap *idmap,
355 struct inode *dir, struct dentry *dentry,
359 struct v9fs_session_info *v9ses;
360 struct p9_fid *fid = NULL, *dfid = NULL;
362 const unsigned char *name;
366 struct posix_acl *dacl = NULL, *pacl = NULL;
368 p9_debug(P9_DEBUG_VFS, "name %pd\n", dentry);
369 v9ses = v9fs_inode2v9ses(dir);
372 if (dir->i_mode & S_ISGID)
375 dfid = v9fs_parent_fid(dentry);
378 p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
382 gid = v9fs_get_fsgid_for_create(dir);
384 /* Update mode based on ACL value */
385 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
387 p9_debug(P9_DEBUG_VFS, "Failed to get acl values in mkdir %d\n",
391 name = dentry->d_name.name;
392 err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid);
395 fid = p9_client_walk(dfid, 1, &name, 1);
398 p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
403 /* instantiate inode and assign the unopened fid to the dentry */
404 if (v9ses->cache & (CACHE_META|CACHE_LOOSE)) {
405 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
407 err = PTR_ERR(inode);
408 p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",
412 v9fs_fid_add(dentry, &fid);
413 v9fs_set_create_acl(inode, fid, dacl, pacl);
414 d_instantiate(dentry, inode);
418 * Not in cached mode. No need to populate
419 * inode with stat. We need to get an inode
420 * so that we can set the acl with dentry
422 inode = v9fs_get_inode(dir->i_sb, mode, 0);
424 err = PTR_ERR(inode);
427 v9fs_set_create_acl(inode, fid, dacl, pacl);
428 d_instantiate(dentry, inode);
431 v9fs_invalidate_inode_attr(dir);
434 v9fs_put_acl(dacl, pacl);
440 v9fs_vfs_getattr_dotl(struct mnt_idmap *idmap,
441 const struct path *path, struct kstat *stat,
442 u32 request_mask, unsigned int flags)
444 struct dentry *dentry = path->dentry;
445 struct v9fs_session_info *v9ses;
447 struct inode *inode = d_inode(dentry);
448 struct p9_stat_dotl *st;
450 p9_debug(P9_DEBUG_VFS, "dentry: %p\n", dentry);
451 v9ses = v9fs_dentry2v9ses(dentry);
452 if (v9ses->cache & (CACHE_META|CACHE_LOOSE)) {
453 generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat);
455 } else if (v9ses->cache) {
456 if (S_ISREG(inode->i_mode)) {
457 int retval = filemap_fdatawrite(inode->i_mapping);
460 p9_debug(P9_DEBUG_ERROR,
461 "flushing writeback during getattr returned %d\n", retval);
464 fid = v9fs_fid_lookup(dentry);
468 /* Ask for all the fields in stat structure. Server will return
469 * whatever it supports
472 st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
477 v9fs_stat2inode_dotl(st, d_inode(dentry), 0);
478 generic_fillattr(&nop_mnt_idmap, request_mask, d_inode(dentry), stat);
479 /* Change block size to what the server returned */
480 stat->blksize = st->st_blksize;
489 #define P9_ATTR_MODE (1 << 0)
490 #define P9_ATTR_UID (1 << 1)
491 #define P9_ATTR_GID (1 << 2)
492 #define P9_ATTR_SIZE (1 << 3)
493 #define P9_ATTR_ATIME (1 << 4)
494 #define P9_ATTR_MTIME (1 << 5)
495 #define P9_ATTR_CTIME (1 << 6)
496 #define P9_ATTR_ATIME_SET (1 << 7)
497 #define P9_ATTR_MTIME_SET (1 << 8)
499 struct dotl_iattr_map {
504 static int v9fs_mapped_iattr_valid(int iattr_valid)
507 int p9_iattr_valid = 0;
508 struct dotl_iattr_map dotl_iattr_map[] = {
509 { ATTR_MODE, P9_ATTR_MODE },
510 { ATTR_UID, P9_ATTR_UID },
511 { ATTR_GID, P9_ATTR_GID },
512 { ATTR_SIZE, P9_ATTR_SIZE },
513 { ATTR_ATIME, P9_ATTR_ATIME },
514 { ATTR_MTIME, P9_ATTR_MTIME },
515 { ATTR_CTIME, P9_ATTR_CTIME },
516 { ATTR_ATIME_SET, P9_ATTR_ATIME_SET },
517 { ATTR_MTIME_SET, P9_ATTR_MTIME_SET },
519 for (i = 0; i < ARRAY_SIZE(dotl_iattr_map); i++) {
520 if (iattr_valid & dotl_iattr_map[i].iattr_valid)
521 p9_iattr_valid |= dotl_iattr_map[i].p9_iattr_valid;
523 return p9_iattr_valid;
527 * v9fs_vfs_setattr_dotl - set file metadata
528 * @idmap: idmap of the mount
529 * @dentry: file whose metadata to set
530 * @iattr: metadata assignment structure
534 int v9fs_vfs_setattr_dotl(struct mnt_idmap *idmap,
535 struct dentry *dentry, struct iattr *iattr)
537 int retval, use_dentry = 0;
538 struct inode *inode = d_inode(dentry);
539 struct v9fs_session_info __maybe_unused *v9ses;
540 struct p9_fid *fid = NULL;
541 struct p9_iattr_dotl p9attr = {
546 p9_debug(P9_DEBUG_VFS, "\n");
548 retval = setattr_prepare(&nop_mnt_idmap, dentry, iattr);
552 v9ses = v9fs_dentry2v9ses(dentry);
554 p9attr.valid = v9fs_mapped_iattr_valid(iattr->ia_valid);
555 if (iattr->ia_valid & ATTR_MODE)
556 p9attr.mode = iattr->ia_mode;
557 if (iattr->ia_valid & ATTR_UID)
558 p9attr.uid = iattr->ia_uid;
559 if (iattr->ia_valid & ATTR_GID)
560 p9attr.gid = iattr->ia_gid;
561 if (iattr->ia_valid & ATTR_SIZE)
562 p9attr.size = iattr->ia_size;
563 if (iattr->ia_valid & ATTR_ATIME_SET) {
564 p9attr.atime_sec = iattr->ia_atime.tv_sec;
565 p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
567 if (iattr->ia_valid & ATTR_MTIME_SET) {
568 p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
569 p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
572 if (iattr->ia_valid & ATTR_FILE) {
573 fid = iattr->ia_file->private_data;
577 fid = v9fs_fid_lookup(dentry);
583 /* Write all dirty data */
584 if (S_ISREG(inode->i_mode)) {
585 retval = filemap_fdatawrite(inode->i_mapping);
587 p9_debug(P9_DEBUG_ERROR,
588 "Flushing file prior to setattr failed: %d\n", retval);
591 retval = p9_client_setattr(fid, &p9attr);
598 if ((iattr->ia_valid & ATTR_SIZE) && iattr->ia_size !=
599 i_size_read(inode)) {
600 truncate_setsize(inode, iattr->ia_size);
601 truncate_pagecache(inode, iattr->ia_size);
603 #ifdef CONFIG_9P_FSCACHE
604 if (v9ses->cache & CACHE_FSCACHE)
605 fscache_resize_cookie(v9fs_inode_cookie(V9FS_I(inode)),
610 v9fs_invalidate_inode_attr(inode);
611 setattr_copy(&nop_mnt_idmap, inode, iattr);
612 mark_inode_dirty(inode);
613 if (iattr->ia_valid & ATTR_MODE) {
614 /* We also want to update ACL when we update mode bits */
615 retval = v9fs_acl_chmod(inode, fid);
629 * v9fs_stat2inode_dotl - populate an inode structure with stat info
630 * @stat: stat structure
631 * @inode: inode to populate
632 * @flags: ctrl flags (e.g. V9FS_STAT2INODE_KEEP_ISIZE)
637 v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode,
641 struct v9fs_inode *v9inode = V9FS_I(inode);
643 if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) {
644 inode->i_atime.tv_sec = stat->st_atime_sec;
645 inode->i_atime.tv_nsec = stat->st_atime_nsec;
646 inode->i_mtime.tv_sec = stat->st_mtime_sec;
647 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
648 inode_set_ctime(inode, stat->st_ctime_sec,
649 stat->st_ctime_nsec);
650 inode->i_uid = stat->st_uid;
651 inode->i_gid = stat->st_gid;
652 set_nlink(inode, stat->st_nlink);
654 mode = stat->st_mode & S_IALLUGO;
655 mode |= inode->i_mode & ~S_IALLUGO;
656 inode->i_mode = mode;
658 if (!(flags & V9FS_STAT2INODE_KEEP_ISIZE))
659 v9fs_i_size_write(inode, stat->st_size);
660 inode->i_blocks = stat->st_blocks;
662 if (stat->st_result_mask & P9_STATS_ATIME) {
663 inode->i_atime.tv_sec = stat->st_atime_sec;
664 inode->i_atime.tv_nsec = stat->st_atime_nsec;
666 if (stat->st_result_mask & P9_STATS_MTIME) {
667 inode->i_mtime.tv_sec = stat->st_mtime_sec;
668 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
670 if (stat->st_result_mask & P9_STATS_CTIME) {
671 inode_set_ctime(inode, stat->st_ctime_sec,
672 stat->st_ctime_nsec);
674 if (stat->st_result_mask & P9_STATS_UID)
675 inode->i_uid = stat->st_uid;
676 if (stat->st_result_mask & P9_STATS_GID)
677 inode->i_gid = stat->st_gid;
678 if (stat->st_result_mask & P9_STATS_NLINK)
679 set_nlink(inode, stat->st_nlink);
680 if (stat->st_result_mask & P9_STATS_MODE) {
681 mode = stat->st_mode & S_IALLUGO;
682 mode |= inode->i_mode & ~S_IALLUGO;
683 inode->i_mode = mode;
685 if (!(flags & V9FS_STAT2INODE_KEEP_ISIZE) &&
686 stat->st_result_mask & P9_STATS_SIZE)
687 v9fs_i_size_write(inode, stat->st_size);
688 if (stat->st_result_mask & P9_STATS_BLOCKS)
689 inode->i_blocks = stat->st_blocks;
691 if (stat->st_result_mask & P9_STATS_GEN)
692 inode->i_generation = stat->st_gen;
694 /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION
695 * because the inode structure does not have fields for them.
697 v9inode->cache_validity &= ~V9FS_INO_INVALID_ATTR;
701 v9fs_vfs_symlink_dotl(struct mnt_idmap *idmap, struct inode *dir,
702 struct dentry *dentry, const char *symname)
706 const unsigned char *name;
710 struct p9_fid *fid = NULL;
711 struct v9fs_session_info *v9ses;
713 name = dentry->d_name.name;
714 p9_debug(P9_DEBUG_VFS, "%lu,%s,%s\n", dir->i_ino, name, symname);
715 v9ses = v9fs_inode2v9ses(dir);
717 dfid = v9fs_parent_fid(dentry);
720 p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
724 gid = v9fs_get_fsgid_for_create(dir);
726 /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */
727 err = p9_client_symlink(dfid, name, symname, gid, &qid);
730 p9_debug(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err);
734 v9fs_invalidate_inode_attr(dir);
735 if (v9ses->cache & (CACHE_META|CACHE_LOOSE)) {
736 /* Now walk from the parent so we can get an unopened fid. */
737 fid = p9_client_walk(dfid, 1, &name, 1);
740 p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
745 /* instantiate inode and assign the unopened fid to dentry */
746 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
748 err = PTR_ERR(inode);
749 p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",
753 v9fs_fid_add(dentry, &fid);
754 d_instantiate(dentry, inode);
757 /* Not in cached mode. No need to populate inode with stat */
758 inode = v9fs_get_inode(dir->i_sb, S_IFLNK, 0);
760 err = PTR_ERR(inode);
763 d_instantiate(dentry, inode);
773 * v9fs_vfs_link_dotl - create a hardlink for dotl
774 * @old_dentry: dentry for file to link to
775 * @dir: inode destination for new link
776 * @dentry: dentry for link
781 v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
782 struct dentry *dentry)
785 struct p9_fid *dfid, *oldfid;
786 struct v9fs_session_info *v9ses;
788 p9_debug(P9_DEBUG_VFS, "dir ino: %lu, old_name: %pd, new_name: %pd\n",
789 dir->i_ino, old_dentry, dentry);
791 v9ses = v9fs_inode2v9ses(dir);
792 dfid = v9fs_parent_fid(dentry);
794 return PTR_ERR(dfid);
796 oldfid = v9fs_fid_lookup(old_dentry);
797 if (IS_ERR(oldfid)) {
799 return PTR_ERR(oldfid);
802 err = p9_client_link(dfid, oldfid, dentry->d_name.name);
807 p9_debug(P9_DEBUG_VFS, "p9_client_link failed %d\n", err);
811 v9fs_invalidate_inode_attr(dir);
812 if (v9ses->cache & (CACHE_META|CACHE_LOOSE)) {
813 /* Get the latest stat info from server. */
816 fid = v9fs_fid_lookup(old_dentry);
820 v9fs_refresh_inode_dotl(fid, d_inode(old_dentry));
823 ihold(d_inode(old_dentry));
824 d_instantiate(dentry, d_inode(old_dentry));
830 * v9fs_vfs_mknod_dotl - create a special file
831 * @idmap: The idmap of the mount
832 * @dir: inode destination for new link
833 * @dentry: dentry for file
834 * @omode: mode for creation
835 * @rdev: device associated with special file
839 v9fs_vfs_mknod_dotl(struct mnt_idmap *idmap, struct inode *dir,
840 struct dentry *dentry, umode_t omode, dev_t rdev)
844 const unsigned char *name;
846 struct v9fs_session_info *v9ses;
847 struct p9_fid *fid = NULL, *dfid = NULL;
850 struct posix_acl *dacl = NULL, *pacl = NULL;
852 p9_debug(P9_DEBUG_VFS, " %lu,%pd mode: %x MAJOR: %u MINOR: %u\n",
853 dir->i_ino, dentry, omode,
854 MAJOR(rdev), MINOR(rdev));
856 v9ses = v9fs_inode2v9ses(dir);
857 dfid = v9fs_parent_fid(dentry);
860 p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
864 gid = v9fs_get_fsgid_for_create(dir);
866 /* Update mode based on ACL value */
867 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
869 p9_debug(P9_DEBUG_VFS, "Failed to get acl values in mknod %d\n",
873 name = dentry->d_name.name;
875 err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid);
879 v9fs_invalidate_inode_attr(dir);
880 fid = p9_client_walk(dfid, 1, &name, 1);
883 p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
888 /* instantiate inode and assign the unopened fid to the dentry */
889 if (v9ses->cache & (CACHE_META|CACHE_LOOSE)) {
890 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
892 err = PTR_ERR(inode);
893 p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",
897 v9fs_set_create_acl(inode, fid, dacl, pacl);
898 v9fs_fid_add(dentry, &fid);
899 d_instantiate(dentry, inode);
903 * Not in cached mode. No need to populate inode with stat.
904 * socket syscall returns a fd, so we need instantiate
906 inode = v9fs_get_inode(dir->i_sb, mode, rdev);
908 err = PTR_ERR(inode);
911 v9fs_set_create_acl(inode, fid, dacl, pacl);
912 d_instantiate(dentry, inode);
916 v9fs_put_acl(dacl, pacl);
923 * v9fs_vfs_get_link_dotl - follow a symlink path
924 * @dentry: dentry for symlink
925 * @inode: inode for symlink
926 * @done: destructor for return value
930 v9fs_vfs_get_link_dotl(struct dentry *dentry,
932 struct delayed_call *done)
939 return ERR_PTR(-ECHILD);
941 p9_debug(P9_DEBUG_VFS, "%pd\n", dentry);
943 fid = v9fs_fid_lookup(dentry);
945 return ERR_CAST(fid);
946 retval = p9_client_readlink(fid, &target);
949 return ERR_PTR(retval);
950 set_delayed_call(done, kfree_link, target);
954 int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode)
956 struct p9_stat_dotl *st;
957 struct v9fs_session_info *v9ses;
960 v9ses = v9fs_inode2v9ses(inode);
961 st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
965 * Don't update inode if the file type is different
967 if (inode_wrong_type(inode, st->st_mode))
971 * We don't want to refresh inode->i_size,
972 * because we may have cached data
974 flags = (v9ses->cache & CACHE_LOOSE) ?
975 V9FS_STAT2INODE_KEEP_ISIZE : 0;
976 v9fs_stat2inode_dotl(st, inode, flags);
982 const struct inode_operations v9fs_dir_inode_operations_dotl = {
983 .create = v9fs_vfs_create_dotl,
984 .atomic_open = v9fs_vfs_atomic_open_dotl,
985 .lookup = v9fs_vfs_lookup,
986 .link = v9fs_vfs_link_dotl,
987 .symlink = v9fs_vfs_symlink_dotl,
988 .unlink = v9fs_vfs_unlink,
989 .mkdir = v9fs_vfs_mkdir_dotl,
990 .rmdir = v9fs_vfs_rmdir,
991 .mknod = v9fs_vfs_mknod_dotl,
992 .rename = v9fs_vfs_rename,
993 .getattr = v9fs_vfs_getattr_dotl,
994 .setattr = v9fs_vfs_setattr_dotl,
995 .listxattr = v9fs_listxattr,
996 .get_inode_acl = v9fs_iop_get_inode_acl,
997 .get_acl = v9fs_iop_get_acl,
998 .set_acl = v9fs_iop_set_acl,
1001 const struct inode_operations v9fs_file_inode_operations_dotl = {
1002 .getattr = v9fs_vfs_getattr_dotl,
1003 .setattr = v9fs_vfs_setattr_dotl,
1004 .listxattr = v9fs_listxattr,
1005 .get_inode_acl = v9fs_iop_get_inode_acl,
1006 .get_acl = v9fs_iop_get_acl,
1007 .set_acl = v9fs_iop_set_acl,
1010 const struct inode_operations v9fs_symlink_inode_operations_dotl = {
1011 .get_link = v9fs_vfs_get_link_dotl,
1012 .getattr = v9fs_vfs_getattr_dotl,
1013 .setattr = v9fs_vfs_setattr_dotl,
1014 .listxattr = v9fs_listxattr,