^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/fs/9p/vfs_super.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * This file contians superblock ops for 9P2000. It is intended that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * you mount this file system on directories.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/idr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/statfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/magic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <net/9p/9p.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <net/9p/client.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include "v9fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include "v9fs_vfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include "fid.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include "xattr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include "acl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static const struct super_operations v9fs_super_ops, v9fs_super_ops_dotl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * v9fs_set_super - set the superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * @s: super block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * @data: file system specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static int v9fs_set_super(struct super_block *s, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) s->s_fs_info = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return set_anon_super(s, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * v9fs_fill_super - populate superblock with info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * @sb: superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * @v9ses: session information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * @flags: flags propagated from v9fs_mount()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) v9fs_fill_super(struct super_block *sb, struct v9fs_session_info *v9ses,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) sb->s_maxbytes = MAX_LFS_FILESIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) sb->s_blocksize_bits = fls(v9ses->maxdata - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) sb->s_blocksize = 1 << sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) sb->s_magic = V9FS_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (v9fs_proto_dotl(v9ses)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) sb->s_op = &v9fs_super_ops_dotl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) sb->s_xattr = v9fs_xattr_handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) sb->s_op = &v9fs_super_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) sb->s_time_max = U32_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) sb->s_time_min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) ret = super_setup_bdi(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (!v9ses->cache) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) sb->s_bdi->ra_pages = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) sb->s_bdi->io_pages = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) sb->s_flags |= SB_ACTIVE | SB_DIRSYNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (!v9ses->cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) sb->s_flags |= SB_SYNCHRONOUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #ifdef CONFIG_9P_FS_POSIX_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if ((v9ses->flags & V9FS_ACL_MASK) == V9FS_POSIX_ACL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) sb->s_flags |= SB_POSIXACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * v9fs_mount - mount a superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * @fs_type: file system type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * @flags: mount flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * @dev_name: device name that was mounted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * @data: mount options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) const char *dev_name, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct super_block *sb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct inode *inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct dentry *root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct v9fs_session_info *v9ses = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) umode_t mode = S_IRWXUGO | S_ISVTX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct p9_fid *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) p9_debug(P9_DEBUG_VFS, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) v9ses = kzalloc(sizeof(struct v9fs_session_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (!v9ses)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) fid = v9fs_session_init(v9ses, dev_name, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (IS_ERR(fid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) retval = PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) goto free_session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) sb = sget(fs_type, NULL, v9fs_set_super, flags, v9ses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (IS_ERR(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) retval = PTR_ERR(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) goto clunk_fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) retval = v9fs_fill_super(sb, v9ses, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) goto release_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) sb->s_d_op = &v9fs_cached_dentry_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) sb->s_d_op = &v9fs_dentry_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) inode = v9fs_get_inode(sb, S_IFDIR | mode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) retval = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) goto release_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) root = d_make_root(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (!root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) goto release_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) sb->s_root = root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (v9fs_proto_dotl(v9ses)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct p9_stat_dotl *st = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (IS_ERR(st)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) retval = PTR_ERR(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) goto release_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) d_inode(root)->i_ino = v9fs_qid2ino(&st->qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) v9fs_stat2inode_dotl(st, d_inode(root), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) kfree(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct p9_wstat *st = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) st = p9_client_stat(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (IS_ERR(st)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) retval = PTR_ERR(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) goto release_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) d_inode(root)->i_ino = v9fs_qid2ino(&st->qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) v9fs_stat2inode(st, d_inode(root), sb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) p9stat_free(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) kfree(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) retval = v9fs_get_acl(inode, fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) goto release_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) v9fs_fid_add(root, fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) p9_debug(P9_DEBUG_VFS, " simple set mount, return 0\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return dget(sb->s_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) clunk_fid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) p9_client_clunk(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) v9fs_session_close(v9ses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) free_session:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) kfree(v9ses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) return ERR_PTR(retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) release_sb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * we will do the session_close and root dentry release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * in the below call. But we need to clunk fid, because we haven't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * attached the fid to dentry so it won't get clunked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * automatically.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) p9_client_clunk(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) deactivate_locked_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return ERR_PTR(retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * v9fs_kill_super - Kill Superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * @s: superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static void v9fs_kill_super(struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct v9fs_session_info *v9ses = s->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) p9_debug(P9_DEBUG_VFS, " %p\n", s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) kill_anon_super(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) v9fs_session_cancel(v9ses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) v9fs_session_close(v9ses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) kfree(v9ses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) s->s_fs_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) p9_debug(P9_DEBUG_VFS, "exiting kill_super\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) v9fs_umount_begin(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) v9ses = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) v9fs_session_begin_cancel(v9ses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static int v9fs_statfs(struct dentry *dentry, struct kstatfs *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct p9_fid *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct p9_rstatfs rs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) fid = v9fs_fid_lookup(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (IS_ERR(fid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) res = PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) v9ses = v9fs_dentry2v9ses(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (v9fs_proto_dotl(v9ses)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) res = p9_client_statfs(fid, &rs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (res == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) buf->f_type = rs.type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) buf->f_bsize = rs.bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) buf->f_blocks = rs.blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) buf->f_bfree = rs.bfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) buf->f_bavail = rs.bavail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) buf->f_files = rs.files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) buf->f_ffree = rs.ffree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) buf->f_fsid = u64_to_fsid(rs.fsid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) buf->f_namelen = rs.namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (res != -ENOSYS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) res = simple_statfs(dentry, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static int v9fs_drop_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) v9ses = v9fs_inode2v9ses(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return generic_drop_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * in case of non cached mode always drop the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * the inode because we want the inode attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * to always match that on the server.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static int v9fs_write_inode(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) struct p9_wstat wstat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) struct v9fs_inode *v9inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) * send an fsync request to server irrespective of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * wbc->sync_mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) p9_debug(P9_DEBUG_VFS, "%s: inode %p\n", __func__, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) v9inode = V9FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (!v9inode->writeback_fid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) v9fs_blank_wstat(&wstat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) ret = p9_client_wstat(v9inode->writeback_fid, &wstat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) static int v9fs_write_inode_dotl(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) struct v9fs_inode *v9inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * send an fsync request to server irrespective of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) * wbc->sync_mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) v9inode = V9FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) p9_debug(P9_DEBUG_VFS, "%s: inode %p, writeback_fid %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) __func__, inode, v9inode->writeback_fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (!v9inode->writeback_fid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) ret = p9_client_fsync(v9inode->writeback_fid, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) static const struct super_operations v9fs_super_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) .alloc_inode = v9fs_alloc_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) .free_inode = v9fs_free_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) .statfs = simple_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) .evict_inode = v9fs_evict_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) .show_options = v9fs_show_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) .umount_begin = v9fs_umount_begin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) .write_inode = v9fs_write_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) static const struct super_operations v9fs_super_ops_dotl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) .alloc_inode = v9fs_alloc_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) .free_inode = v9fs_free_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) .statfs = v9fs_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) .drop_inode = v9fs_drop_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) .evict_inode = v9fs_evict_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) .show_options = v9fs_show_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) .umount_begin = v9fs_umount_begin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) .write_inode = v9fs_write_inode_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) struct file_system_type v9fs_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) .name = "9p",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) .mount = v9fs_mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) .kill_sb = v9fs_kill_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) .fs_flags = FS_RENAME_DOES_D_MOVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) MODULE_ALIAS_FS("9p");