^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_inode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * This file contains vfs inode ops for the 9P2000 protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^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/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/namei.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/xattr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/posix_acl.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 "cache.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include "xattr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include "acl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static const struct inode_operations v9fs_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static const struct inode_operations v9fs_dir_inode_operations_dotu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static const struct inode_operations v9fs_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static const struct inode_operations v9fs_symlink_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * unixmode2p9mode - convert unix mode bits to plan 9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * @v9ses: v9fs session information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * @mode: mode to convert
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static u32 unixmode2p9mode(struct v9fs_session_info *v9ses, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) res = mode & 0777;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (S_ISDIR(mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) res |= P9_DMDIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (v9fs_proto_dotu(v9ses)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) if (v9ses->nodev == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if (S_ISSOCK(mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) res |= P9_DMSOCKET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (S_ISFIFO(mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) res |= P9_DMNAMEDPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (S_ISBLK(mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) res |= P9_DMDEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (S_ISCHR(mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) res |= P9_DMDEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if ((mode & S_ISUID) == S_ISUID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) res |= P9_DMSETUID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if ((mode & S_ISGID) == S_ISGID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) res |= P9_DMSETGID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if ((mode & S_ISVTX) == S_ISVTX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) res |= P9_DMSETVTX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) return res;
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * p9mode2perm- convert plan9 mode bits to unix permission bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * @v9ses: v9fs session information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * @stat: p9_wstat from which mode need to be derived
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static int p9mode2perm(struct v9fs_session_info *v9ses,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct p9_wstat *stat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int mode = stat->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) res = mode & S_IALLUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (v9fs_proto_dotu(v9ses)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if ((mode & P9_DMSETUID) == P9_DMSETUID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) res |= S_ISUID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if ((mode & P9_DMSETGID) == P9_DMSETGID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) res |= S_ISGID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if ((mode & P9_DMSETVTX) == P9_DMSETVTX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) res |= S_ISVTX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * p9mode2unixmode- convert plan9 mode bits to unix mode bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * @v9ses: v9fs session information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * @stat: p9_wstat from which mode need to be derived
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * @rdev: major number, minor number in case of device files.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static umode_t p9mode2unixmode(struct v9fs_session_info *v9ses,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct p9_wstat *stat, dev_t *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) u32 mode = stat->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) *rdev = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) res = p9mode2perm(v9ses, stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if ((mode & P9_DMDIR) == P9_DMDIR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) res |= S_IFDIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) else if ((mode & P9_DMSYMLINK) && (v9fs_proto_dotu(v9ses)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) res |= S_IFLNK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) else if ((mode & P9_DMSOCKET) && (v9fs_proto_dotu(v9ses))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) && (v9ses->nodev == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) res |= S_IFSOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) else if ((mode & P9_DMNAMEDPIPE) && (v9fs_proto_dotu(v9ses))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) && (v9ses->nodev == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) res |= S_IFIFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) else if ((mode & P9_DMDEVICE) && (v9fs_proto_dotu(v9ses))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) && (v9ses->nodev == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) char type = 0, ext[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int major = -1, minor = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) strlcpy(ext, stat->extension, sizeof(ext));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) sscanf(ext, "%c %i %i", &type, &major, &minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) case 'c':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) res |= S_IFCHR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) case 'b':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) res |= S_IFBLK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) p9_debug(P9_DEBUG_ERROR, "Unknown special type %c %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) type, stat->extension);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) *rdev = MKDEV(major, minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) res |= S_IFREG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * v9fs_uflags2omode- convert posix open flags to plan 9 mode bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * @uflags: flags to convert
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * @extended: if .u extensions are active
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) int v9fs_uflags2omode(int uflags, int extended)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) switch (uflags&3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) case O_RDONLY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) ret = P9_OREAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) case O_WRONLY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) ret = P9_OWRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) case O_RDWR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) ret = P9_ORDWR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (extended) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (uflags & O_EXCL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) ret |= P9_OEXCL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (uflags & O_APPEND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ret |= P9_OAPPEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * v9fs_blank_wstat - helper function to setup a 9P stat structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * @wstat: structure to initialize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) v9fs_blank_wstat(struct p9_wstat *wstat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) wstat->type = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) wstat->dev = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) wstat->qid.type = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) wstat->qid.version = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) *((long long *)&wstat->qid.path) = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) wstat->mode = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) wstat->atime = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) wstat->mtime = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) wstat->length = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) wstat->name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) wstat->uid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) wstat->gid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) wstat->muid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) wstat->n_uid = INVALID_UID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) wstat->n_gid = INVALID_GID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) wstat->n_muid = INVALID_UID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) wstat->extension = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * v9fs_alloc_inode - helper function to allocate an inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct inode *v9fs_alloc_inode(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct v9fs_inode *v9inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) v9inode = kmem_cache_alloc(v9fs_inode_cache, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (!v9inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) #ifdef CONFIG_9P_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) v9inode->fscache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) mutex_init(&v9inode->fscache_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) v9inode->writeback_fid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) v9inode->cache_validity = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) mutex_init(&v9inode->v_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return &v9inode->vfs_inode;
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * v9fs_free_inode - destroy an inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) void v9fs_free_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) kmem_cache_free(v9fs_inode_cache, V9FS_I(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) int v9fs_init_inode(struct v9fs_session_info *v9ses,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) struct inode *inode, umode_t mode, dev_t rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) inode_init_owner(inode, NULL, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) inode->i_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) inode->i_rdev = rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) inode->i_mapping->a_ops = &v9fs_addr_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) switch (mode & S_IFMT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) case S_IFIFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) case S_IFBLK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) case S_IFCHR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) case S_IFSOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (v9fs_proto_dotl(v9ses)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) inode->i_op = &v9fs_file_inode_operations_dotl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) } else if (v9fs_proto_dotu(v9ses)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) inode->i_op = &v9fs_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) p9_debug(P9_DEBUG_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) "special files without extended mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) init_special_inode(inode, inode->i_mode, inode->i_rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) case S_IFREG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (v9fs_proto_dotl(v9ses)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) inode->i_op = &v9fs_file_inode_operations_dotl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (v9ses->cache == CACHE_LOOSE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) v9ses->cache == CACHE_FSCACHE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) inode->i_fop =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) &v9fs_cached_file_operations_dotl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) else if (v9ses->cache == CACHE_MMAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) inode->i_fop = &v9fs_mmap_file_operations_dotl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) inode->i_fop = &v9fs_file_operations_dotl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) inode->i_op = &v9fs_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (v9ses->cache == CACHE_LOOSE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) v9ses->cache == CACHE_FSCACHE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) inode->i_fop =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) &v9fs_cached_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) else if (v9ses->cache == CACHE_MMAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) inode->i_fop = &v9fs_mmap_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) inode->i_fop = &v9fs_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) case S_IFLNK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) p9_debug(P9_DEBUG_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) "extended modes used with legacy protocol\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (v9fs_proto_dotl(v9ses))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) inode->i_op = &v9fs_symlink_inode_operations_dotl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) inode->i_op = &v9fs_symlink_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) case S_IFDIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) inc_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (v9fs_proto_dotl(v9ses))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) inode->i_op = &v9fs_dir_inode_operations_dotl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) else if (v9fs_proto_dotu(v9ses))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) inode->i_op = &v9fs_dir_inode_operations_dotu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) inode->i_op = &v9fs_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (v9fs_proto_dotl(v9ses))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) inode->i_fop = &v9fs_dir_operations_dotl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) inode->i_fop = &v9fs_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) p9_debug(P9_DEBUG_ERROR, "BAD mode 0x%hx S_IFMT 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) mode, mode & S_IFMT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) * v9fs_get_inode - helper function to setup an inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * @sb: superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * @mode: mode to setup inode with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) struct inode *v9fs_get_inode(struct super_block *sb, umode_t mode, dev_t rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) struct v9fs_session_info *v9ses = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) p9_debug(P9_DEBUG_VFS, "super block: %p mode: %ho\n", sb, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) inode = new_inode(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) if (!inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) pr_warn("%s (%d): Problem allocating inode\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) __func__, task_pid_nr(current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) err = v9fs_init_inode(v9ses, inode, mode, rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) * v9fs_clear_inode - release an inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) * @inode: inode to release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) void v9fs_evict_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) struct v9fs_inode *v9inode = V9FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) truncate_inode_pages_final(&inode->i_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) clear_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) filemap_fdatawrite(&inode->i_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) v9fs_cache_inode_put_cookie(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) /* clunk the fid stashed in writeback_fid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) if (v9inode->writeback_fid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) p9_client_clunk(v9inode->writeback_fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) v9inode->writeback_fid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) static int v9fs_test_inode(struct inode *inode, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) int umode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) dev_t rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) struct v9fs_inode *v9inode = V9FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) struct p9_wstat *st = (struct p9_wstat *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) umode = p9mode2unixmode(v9ses, st, &rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) /* don't match inode of different type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (inode_wrong_type(inode, umode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) /* compare qid details */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (memcmp(&v9inode->qid.version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) &st->qid.version, sizeof(v9inode->qid.version)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (v9inode->qid.type != st->qid.type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) if (v9inode->qid.path != st->qid.path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) static int v9fs_test_new_inode(struct inode *inode, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) static int v9fs_set_inode(struct inode *inode, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) struct v9fs_inode *v9inode = V9FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) struct p9_wstat *st = (struct p9_wstat *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) memcpy(&v9inode->qid, &st->qid, sizeof(st->qid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) static struct inode *v9fs_qid_iget(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) struct p9_qid *qid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) struct p9_wstat *st,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) int new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) dev_t rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) umode_t umode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) unsigned long i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) struct v9fs_session_info *v9ses = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) int (*test)(struct inode *, void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) if (new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) test = v9fs_test_new_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) test = v9fs_test_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) i_ino = v9fs_qid2ino(qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) inode = iget5_locked(sb, i_ino, test, v9fs_set_inode, st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) if (!(inode->i_state & I_NEW))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) * initialize the inode with the stat info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) * FIXME!! we may need support for stale inodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) * later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) inode->i_ino = i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) umode = p9mode2unixmode(v9ses, st, &rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) retval = v9fs_init_inode(v9ses, inode, umode, rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) v9fs_stat2inode(st, inode, sb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) v9fs_cache_inode_get_cookie(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) unlock_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) iget_failed(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) return ERR_PTR(retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) struct inode *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) struct super_block *sb, int new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) struct p9_wstat *st;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) struct inode *inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) st = p9_client_stat(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) if (IS_ERR(st))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) return ERR_CAST(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) inode = v9fs_qid_iget(sb, &st->qid, st, new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) p9stat_free(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) kfree(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) * v9fs_at_to_dotl_flags- convert Linux specific AT flags to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) * plan 9 AT flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) * @flags: flags to convert
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) static int v9fs_at_to_dotl_flags(int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) int rflags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) if (flags & AT_REMOVEDIR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) rflags |= P9_DOTL_AT_REMOVEDIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) return rflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) * v9fs_dec_count - helper functon to drop i_nlink.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) * If a directory had nlink <= 2 (including . and ..), then we should not drop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) * the link count, which indicates the underlying exported fs doesn't maintain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) * nlink accurately. e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) * - overlayfs sets nlink to 1 for merged dir
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) * - ext4 (with dir_nlink feature enabled) sets nlink to 1 if a dir has more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) * than EXT4_LINK_MAX (65000) links.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) * @inode: inode whose nlink is being dropped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) static void v9fs_dec_count(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) if (!S_ISDIR(inode->i_mode) || inode->i_nlink > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) drop_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) * v9fs_remove - helper function to remove files and directories
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) * @dir: directory inode that is being deleted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) * @dentry: dentry that is being deleted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) * @flags: removing a directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) static int v9fs_remove(struct inode *dir, struct dentry *dentry, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) int retval = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) struct p9_fid *v9fid, *dfid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) p9_debug(P9_DEBUG_VFS, "inode: %p dentry: %p rmdir: %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) dir, dentry, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) v9ses = v9fs_inode2v9ses(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) dfid = v9fs_parent_fid(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) if (IS_ERR(dfid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) retval = PTR_ERR(dfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) if (v9fs_proto_dotl(v9ses))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) retval = p9_client_unlinkat(dfid, dentry->d_name.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) v9fs_at_to_dotl_flags(flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) if (retval == -EOPNOTSUPP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) /* Try the one based on path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) v9fid = v9fs_fid_clone(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) if (IS_ERR(v9fid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) return PTR_ERR(v9fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) retval = p9_client_remove(v9fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) if (!retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) * directories on unlink should have zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) * link count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) if (flags & AT_REMOVEDIR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) clear_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) v9fs_dec_count(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) v9fs_dec_count(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) v9fs_invalidate_inode_attr(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) v9fs_invalidate_inode_attr(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) * v9fs_create - Create a file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) * @v9ses: session information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) * @dir: directory that dentry is being created in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) * @dentry: dentry that is being created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) * @extension: 9p2000.u extension string to support devices, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) * @perm: create permissions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) * @mode: open mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) static struct p9_fid *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) struct dentry *dentry, char *extension, u32 perm, u8 mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) const unsigned char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) struct p9_fid *dfid, *ofid, *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) p9_debug(P9_DEBUG_VFS, "name %pd\n", dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) ofid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) fid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) name = dentry->d_name.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) dfid = v9fs_parent_fid(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) if (IS_ERR(dfid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) err = PTR_ERR(dfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) /* clone a fid to use for creation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) ofid = clone_fid(dfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) if (IS_ERR(ofid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) err = PTR_ERR(ofid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) err = p9_client_fcreate(ofid, name, perm, mode, extension);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) p9_debug(P9_DEBUG_VFS, "p9_client_fcreate failed %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) if (!(perm & P9_DMLINK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) /* now walk from the parent so we can get unopened fid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) fid = p9_client_walk(dfid, 1, &name, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) if (IS_ERR(fid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) err = PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) p9_debug(P9_DEBUG_VFS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) "p9_client_walk failed %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) fid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) * instantiate inode and assign the unopened fid to the dentry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) err = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) p9_debug(P9_DEBUG_VFS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) "inode creation failed %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) v9fs_fid_add(dentry, fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) return ofid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) if (ofid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) p9_client_clunk(ofid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) if (fid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) p9_client_clunk(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) * v9fs_vfs_create - VFS hook to create a regular file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) * open(.., O_CREAT) is handled in v9fs_vfs_atomic_open(). This is only called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) * for mknod(2).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) * @dir: directory inode that is being created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) * @dentry: dentry that is being deleted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) * @mode: create permissions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) v9fs_vfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) bool excl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) u32 perm = unixmode2p9mode(v9ses, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) struct p9_fid *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) /* P9_OEXCL? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) fid = v9fs_create(v9ses, dir, dentry, NULL, perm, P9_ORDWR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) if (IS_ERR(fid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) return PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) v9fs_invalidate_inode_attr(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) p9_client_clunk(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) * v9fs_vfs_mkdir - VFS mkdir hook to create a directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) * @dir: inode that is being unlinked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) * @dentry: dentry that is being unlinked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) * @mode: mode for new directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) u32 perm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) struct p9_fid *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) p9_debug(P9_DEBUG_VFS, "name %pd\n", dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) v9ses = v9fs_inode2v9ses(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) perm = unixmode2p9mode(v9ses, mode | S_IFDIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) fid = v9fs_create(v9ses, dir, dentry, NULL, perm, P9_OREAD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) if (IS_ERR(fid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) err = PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) fid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) inc_nlink(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) v9fs_invalidate_inode_attr(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) if (fid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) p9_client_clunk(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) * @dir: inode that is being walked from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) * @dentry: dentry that is being walked to?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) * @flags: lookup flags (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) struct dentry *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) struct p9_fid *dfid, *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) const unsigned char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) p9_debug(P9_DEBUG_VFS, "dir: %p dentry: (%pd) %p flags: %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) dir, dentry, dentry, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) if (dentry->d_name.len > NAME_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) return ERR_PTR(-ENAMETOOLONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) v9ses = v9fs_inode2v9ses(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) /* We can walk d_parent because we hold the dir->i_mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) dfid = v9fs_parent_fid(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) if (IS_ERR(dfid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) return ERR_CAST(dfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) * Make sure we don't use a wrong inode due to parallel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) * unlink. For cached mode create calls request for new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) * inode. But with cache disabled, lookup should do this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) name = dentry->d_name.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) fid = p9_client_walk(dfid, 1, &name, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) if (fid == ERR_PTR(-ENOENT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) else if (IS_ERR(fid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) inode = ERR_CAST(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) else if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) * If we had a rename on the server and a parallel lookup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) * for the new name, then make sure we instantiate with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) * the new name. ie look up for a/b, while on server somebody
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) * moved b under k and client parallely did a lookup for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) * k/b.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) res = d_splice_alias(inode, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) if (!IS_ERR(fid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) if (!res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) v9fs_fid_add(dentry, fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) else if (!IS_ERR(res))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) v9fs_fid_add(res, fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) p9_client_clunk(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) struct file *file, unsigned flags, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) u32 perm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) struct v9fs_inode *v9inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) struct p9_fid *fid, *inode_fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) struct dentry *res = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) if (d_in_lookup(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) res = v9fs_vfs_lookup(dir, dentry, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) if (IS_ERR(res))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) return PTR_ERR(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) dentry = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) /* Only creates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) if (!(flags & O_CREAT) || d_really_is_positive(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) return finish_no_open(file, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) v9ses = v9fs_inode2v9ses(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) perm = unixmode2p9mode(v9ses, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) fid = v9fs_create(v9ses, dir, dentry, NULL, perm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) v9fs_uflags2omode(flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) v9fs_proto_dotu(v9ses)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) if (IS_ERR(fid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) err = PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) fid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) v9fs_invalidate_inode_attr(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) v9inode = V9FS_I(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) mutex_lock(&v9inode->v_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) if ((v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) !v9inode->writeback_fid &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) ((flags & O_ACCMODE) != O_RDONLY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) * clone a fid and add it to writeback_fid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) * we do it during open time instead of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) * page dirty time via write_begin/page_mkwrite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) * because we want write after unlink usecase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) * to work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) inode_fid = v9fs_writeback_fid(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) if (IS_ERR(inode_fid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) err = PTR_ERR(inode_fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) mutex_unlock(&v9inode->v_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) v9inode->writeback_fid = (void *) inode_fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) mutex_unlock(&v9inode->v_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) err = finish_open(file, dentry, generic_file_open);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) file->private_data = fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) v9fs_cache_inode_set_cookie(d_inode(dentry), file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) file->f_mode |= FMODE_CREATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) dput(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) if (fid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) p9_client_clunk(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) * v9fs_vfs_unlink - VFS unlink hook to delete an inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) * @i: inode that is being unlinked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) * @d: dentry that is being unlinked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) int v9fs_vfs_unlink(struct inode *i, struct dentry *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) return v9fs_remove(i, d, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) * v9fs_vfs_rmdir - VFS unlink hook to delete a directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) * @i: inode that is being unlinked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) * @d: dentry that is being unlinked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) int v9fs_vfs_rmdir(struct inode *i, struct dentry *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) return v9fs_remove(i, d, AT_REMOVEDIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) * v9fs_vfs_rename - VFS hook to rename an inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) * @old_dir: old dir inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) * @old_dentry: old dentry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) * @new_dir: new dir inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) * @new_dentry: new dentry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) struct inode *new_dir, struct dentry *new_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) struct inode *old_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) struct inode *new_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) struct p9_fid *oldfid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) struct p9_fid *olddirfid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) struct p9_fid *newdirfid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) struct p9_wstat wstat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) if (flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) p9_debug(P9_DEBUG_VFS, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) old_inode = d_inode(old_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) new_inode = d_inode(new_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) v9ses = v9fs_inode2v9ses(old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) oldfid = v9fs_fid_lookup(old_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) if (IS_ERR(oldfid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) return PTR_ERR(oldfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) olddirfid = clone_fid(v9fs_parent_fid(old_dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) if (IS_ERR(olddirfid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) retval = PTR_ERR(olddirfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) newdirfid = clone_fid(v9fs_parent_fid(new_dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) if (IS_ERR(newdirfid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) retval = PTR_ERR(newdirfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) goto clunk_olddir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) down_write(&v9ses->rename_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) if (v9fs_proto_dotl(v9ses)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) retval = p9_client_renameat(olddirfid, old_dentry->d_name.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) newdirfid, new_dentry->d_name.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) if (retval == -EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) retval = p9_client_rename(oldfid, newdirfid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) new_dentry->d_name.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) if (retval != -EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) goto clunk_newdir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) if (old_dentry->d_parent != new_dentry->d_parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) * 9P .u can only handle file rename in the same directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) p9_debug(P9_DEBUG_ERROR, "old dir and new dir are different\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) retval = -EXDEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) goto clunk_newdir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) v9fs_blank_wstat(&wstat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) wstat.muid = v9ses->uname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) wstat.name = new_dentry->d_name.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) retval = p9_client_wstat(oldfid, &wstat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) clunk_newdir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) if (!retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) if (new_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) if (S_ISDIR(new_inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) clear_nlink(new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) v9fs_dec_count(new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) if (S_ISDIR(old_inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) if (!new_inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) inc_nlink(new_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) v9fs_dec_count(old_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) v9fs_invalidate_inode_attr(old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) v9fs_invalidate_inode_attr(old_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) v9fs_invalidate_inode_attr(new_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) /* successful rename */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) d_move(old_dentry, new_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) up_write(&v9ses->rename_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) p9_client_clunk(newdirfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) clunk_olddir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) p9_client_clunk(olddirfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) * v9fs_vfs_getattr - retrieve file metadata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) * @path: Object to query
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) * @stat: metadata structure to populate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) * @request_mask: Mask of STATX_xxx flags indicating the caller's interests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) * @flags: AT_STATX_xxx setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) v9fs_vfs_getattr(const struct path *path, struct kstat *stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) u32 request_mask, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) struct dentry *dentry = path->dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) struct p9_fid *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) struct p9_wstat *st;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) p9_debug(P9_DEBUG_VFS, "dentry: %p\n", dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) v9ses = v9fs_dentry2v9ses(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) generic_fillattr(d_inode(dentry), stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) fid = v9fs_fid_lookup(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) if (IS_ERR(fid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) return PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) st = p9_client_stat(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) if (IS_ERR(st))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) return PTR_ERR(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) v9fs_stat2inode(st, d_inode(dentry), dentry->d_sb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) generic_fillattr(d_inode(dentry), stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) p9stat_free(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) kfree(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) * v9fs_vfs_setattr - set file metadata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) * @dentry: file whose metadata to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) * @iattr: metadata assignment structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) struct p9_fid *fid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) struct p9_wstat wstat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) p9_debug(P9_DEBUG_VFS, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) retval = setattr_prepare(dentry, iattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) retval = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) v9ses = v9fs_dentry2v9ses(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) if (iattr->ia_valid & ATTR_FILE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) fid = iattr->ia_file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) WARN_ON(!fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) if (!fid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) fid = v9fs_fid_lookup(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) if(IS_ERR(fid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) return PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) v9fs_blank_wstat(&wstat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) if (iattr->ia_valid & ATTR_MODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) wstat.mode = unixmode2p9mode(v9ses, iattr->ia_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) if (iattr->ia_valid & ATTR_MTIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) wstat.mtime = iattr->ia_mtime.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) if (iattr->ia_valid & ATTR_ATIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) wstat.atime = iattr->ia_atime.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) if (iattr->ia_valid & ATTR_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) wstat.length = iattr->ia_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) if (v9fs_proto_dotu(v9ses)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) if (iattr->ia_valid & ATTR_UID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) wstat.n_uid = iattr->ia_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) if (iattr->ia_valid & ATTR_GID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) wstat.n_gid = iattr->ia_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) /* Write all dirty data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) if (d_is_reg(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) filemap_write_and_wait(d_inode(dentry)->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) retval = p9_client_wstat(fid, &wstat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) if ((iattr->ia_valid & ATTR_SIZE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) iattr->ia_size != i_size_read(d_inode(dentry)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) truncate_setsize(d_inode(dentry), iattr->ia_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) v9fs_invalidate_inode_attr(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) setattr_copy(d_inode(dentry), iattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) mark_inode_dirty(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) * v9fs_stat2inode - populate an inode structure with mistat info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) * @stat: Plan 9 metadata (mistat) structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) * @inode: inode to populate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) * @sb: superblock of filesystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) * @flags: control flags (e.g. V9FS_STAT2INODE_KEEP_ISIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) struct super_block *sb, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) umode_t mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) char ext[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) char tag_name[14];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) unsigned int i_nlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) struct v9fs_session_info *v9ses = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) struct v9fs_inode *v9inode = V9FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) set_nlink(inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) inode->i_atime.tv_sec = stat->atime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) inode->i_mtime.tv_sec = stat->mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) inode->i_ctime.tv_sec = stat->mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) inode->i_uid = v9ses->dfltuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) inode->i_gid = v9ses->dfltgid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) if (v9fs_proto_dotu(v9ses)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) inode->i_uid = stat->n_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) inode->i_gid = stat->n_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) if ((S_ISREG(inode->i_mode)) || (S_ISDIR(inode->i_mode))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) if (v9fs_proto_dotu(v9ses) && (stat->extension[0] != '\0')) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) * Hadlink support got added later to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) * to the .u extension. So there can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) * server out there that doesn't support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) * this even with .u extension. So check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) * for non NULL stat->extension
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) strlcpy(ext, stat->extension, sizeof(ext));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) /* HARDLINKCOUNT %u */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) sscanf(ext, "%13s %u", tag_name, &i_nlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) if (!strncmp(tag_name, "HARDLINKCOUNT", 13))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) set_nlink(inode, i_nlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) mode = p9mode2perm(v9ses, stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) mode |= inode->i_mode & ~S_IALLUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) inode->i_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) if (!(flags & V9FS_STAT2INODE_KEEP_ISIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) v9fs_i_size_write(inode, stat->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) /* not real number of blocks, but 512 byte ones ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) inode->i_blocks = (stat->length + 512 - 1) >> 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) v9inode->cache_validity &= ~V9FS_INO_INVALID_ATTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) * v9fs_qid2ino - convert qid into inode number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) * @qid: qid to hash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) * BUG: potential for inode number collisions?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) ino_t v9fs_qid2ino(struct p9_qid *qid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) u64 path = qid->path + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) ino_t i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) if (sizeof(ino_t) == sizeof(path))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) memcpy(&i, &path, sizeof(ino_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) i = (ino_t) (path ^ (path >> 32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) * v9fs_vfs_get_link - follow a symlink path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) * @dentry: dentry for symlink
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) * @inode: inode for symlink
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) * @done: delayed call for when we are done with the return value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) static const char *v9fs_vfs_get_link(struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) struct delayed_call *done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) struct p9_fid *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) struct p9_wstat *st;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) char *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) if (!dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) return ERR_PTR(-ECHILD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) v9ses = v9fs_dentry2v9ses(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) fid = v9fs_fid_lookup(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) p9_debug(P9_DEBUG_VFS, "%pd\n", dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) if (IS_ERR(fid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) return ERR_CAST(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) if (!v9fs_proto_dotu(v9ses))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) return ERR_PTR(-EBADF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) st = p9_client_stat(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) if (IS_ERR(st))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) return ERR_CAST(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) if (!(st->mode & P9_DMSYMLINK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) p9stat_free(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) kfree(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) res = st->extension;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) st->extension = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) if (strlen(res) >= PATH_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) res[PATH_MAX - 1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) p9stat_free(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) kfree(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) set_delayed_call(done, kfree_link, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) * v9fs_vfs_mkspecial - create a special file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) * @dir: inode to create special file in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) * @dentry: dentry to create
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) * @perm: mode to create special file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) * @extension: 9p2000.u format extension string representing special file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) u32 perm, const char *extension)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) struct p9_fid *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) v9ses = v9fs_inode2v9ses(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) if (!v9fs_proto_dotu(v9ses)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) p9_debug(P9_DEBUG_ERROR, "not extended\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) fid = v9fs_create(v9ses, dir, dentry, (char *) extension, perm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) P9_OREAD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) if (IS_ERR(fid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) return PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) v9fs_invalidate_inode_attr(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) p9_client_clunk(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) * v9fs_vfs_symlink - helper function to create symlinks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) * @dir: directory inode containing symlink
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) * @dentry: dentry for symlink
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) * @symname: symlink data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) * See Also: 9P2000.u RFC for more information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) p9_debug(P9_DEBUG_VFS, " %lu,%pd,%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) dir->i_ino, dentry, symname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) return v9fs_vfs_mkspecial(dir, dentry, P9_DMSYMLINK, symname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) #define U32_MAX_DIGITS 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) * v9fs_vfs_link - create a hardlink
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) * @old_dentry: dentry for file to link to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) * @dir: inode destination for new link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) * @dentry: dentry for link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) char name[1 + U32_MAX_DIGITS + 2]; /* sign + number + \n + \0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) struct p9_fid *oldfid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) p9_debug(P9_DEBUG_VFS, " %lu,%pd,%pd\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) dir->i_ino, dentry, old_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) oldfid = v9fs_fid_clone(old_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) if (IS_ERR(oldfid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) return PTR_ERR(oldfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) sprintf(name, "%d\n", oldfid->fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) if (!retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) v9fs_refresh_inode(oldfid, d_inode(old_dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) v9fs_invalidate_inode_attr(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) p9_client_clunk(oldfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) * v9fs_vfs_mknod - create a special file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) * @dir: inode destination for new link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) * @dentry: dentry for file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) * @mode: mode for creation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) * @rdev: device associated with special file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) char name[2 + U32_MAX_DIGITS + 1 + U32_MAX_DIGITS + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) u32 perm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) p9_debug(P9_DEBUG_VFS, " %lu,%pd mode: %hx MAJOR: %u MINOR: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) dir->i_ino, dentry, mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) MAJOR(rdev), MINOR(rdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) /* build extension */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) if (S_ISBLK(mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) sprintf(name, "b %u %u", MAJOR(rdev), MINOR(rdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) else if (S_ISCHR(mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) sprintf(name, "c %u %u", MAJOR(rdev), MINOR(rdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) *name = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) perm = unixmode2p9mode(v9ses, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) retval = v9fs_vfs_mkspecial(dir, dentry, perm, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) int umode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) dev_t rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) struct p9_wstat *st;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) unsigned int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) v9ses = v9fs_inode2v9ses(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) st = p9_client_stat(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) if (IS_ERR(st))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) return PTR_ERR(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) * Don't update inode if the file type is different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) umode = p9mode2unixmode(v9ses, st, &rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) if (inode_wrong_type(inode, umode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) * We don't want to refresh inode->i_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) * because we may have cached data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) flags = (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) V9FS_STAT2INODE_KEEP_ISIZE : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) v9fs_stat2inode(st, inode, inode->i_sb, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) p9stat_free(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) kfree(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) static const struct inode_operations v9fs_dir_inode_operations_dotu = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) .create = v9fs_vfs_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) .lookup = v9fs_vfs_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) .atomic_open = v9fs_vfs_atomic_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) .symlink = v9fs_vfs_symlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) .link = v9fs_vfs_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) .unlink = v9fs_vfs_unlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) .mkdir = v9fs_vfs_mkdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) .rmdir = v9fs_vfs_rmdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) .mknod = v9fs_vfs_mknod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) .rename = v9fs_vfs_rename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) .getattr = v9fs_vfs_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) .setattr = v9fs_vfs_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) static const struct inode_operations v9fs_dir_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) .create = v9fs_vfs_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) .lookup = v9fs_vfs_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) .atomic_open = v9fs_vfs_atomic_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) .unlink = v9fs_vfs_unlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) .mkdir = v9fs_vfs_mkdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) .rmdir = v9fs_vfs_rmdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) .mknod = v9fs_vfs_mknod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) .rename = v9fs_vfs_rename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) .getattr = v9fs_vfs_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) .setattr = v9fs_vfs_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) static const struct inode_operations v9fs_file_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) .getattr = v9fs_vfs_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) .setattr = v9fs_vfs_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) static const struct inode_operations v9fs_symlink_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) .get_link = v9fs_vfs_get_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) .getattr = v9fs_vfs_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) .setattr = v9fs_vfs_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417)