^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_dotl.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.L 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) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/idr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/xattr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/posix_acl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <net/9p/9p.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <net/9p/client.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "v9fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include "v9fs_vfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include "fid.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include "cache.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include "xattr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include "acl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, umode_t omode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) dev_t rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * v9fs_get_fsgid_for_create - Helper function to get the gid for creating a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * new file system object. This checks the S_ISGID to determine the owning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * group of the new file system object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static kgid_t v9fs_get_fsgid_for_create(struct inode *dir_inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) BUG_ON(dir_inode == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (dir_inode->i_mode & S_ISGID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /* set_gid bit is set.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return dir_inode->i_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return current_fsgid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static int v9fs_test_inode_dotl(struct inode *inode, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct v9fs_inode *v9inode = V9FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct p9_stat_dotl *st = (struct p9_stat_dotl *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /* don't match inode of different type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (inode_wrong_type(inode, st->st_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (inode->i_generation != st->st_gen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /* compare qid details */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (memcmp(&v9inode->qid.version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) &st->qid.version, sizeof(v9inode->qid.version)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (v9inode->qid.type != st->qid.type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (v9inode->qid.path != st->qid.path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /* Always get a new inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static int v9fs_test_new_inode_dotl(struct inode *inode, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static int v9fs_set_inode_dotl(struct inode *inode, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct v9fs_inode *v9inode = V9FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct p9_stat_dotl *st = (struct p9_stat_dotl *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) memcpy(&v9inode->qid, &st->qid, sizeof(st->qid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) inode->i_generation = st->st_gen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct p9_qid *qid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct p9_fid *fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct p9_stat_dotl *st,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) int new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) unsigned long i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct v9fs_session_info *v9ses = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) int (*test)(struct inode *, void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) test = v9fs_test_new_inode_dotl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) test = v9fs_test_inode_dotl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) i_ino = v9fs_qid2ino(qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) inode = iget5_locked(sb, i_ino, test, v9fs_set_inode_dotl, st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (!(inode->i_state & I_NEW))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * initialize the inode with the stat info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * FIXME!! we may need support for stale inodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) inode->i_ino = i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) retval = v9fs_init_inode(v9ses, inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) st->st_mode, new_decode_dev(st->st_rdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) v9fs_stat2inode_dotl(st, inode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) v9fs_cache_inode_get_cookie(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) retval = v9fs_get_acl(inode, fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) unlock_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) iget_failed(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return ERR_PTR(retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct inode *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct super_block *sb, int new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct p9_stat_dotl *st;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct inode *inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) st = p9_client_getattr_dotl(fid, P9_STATS_BASIC | P9_STATS_GEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (IS_ERR(st))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return ERR_CAST(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) inode = v9fs_qid_iget_dotl(sb, &st->qid, fid, st, new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) kfree(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct dotl_openflag_map {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) int open_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) int dotl_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static int v9fs_mapped_dotl_flags(int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) int rflags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct dotl_openflag_map dotl_oflag_map[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) { O_CREAT, P9_DOTL_CREATE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) { O_EXCL, P9_DOTL_EXCL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) { O_NOCTTY, P9_DOTL_NOCTTY },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) { O_APPEND, P9_DOTL_APPEND },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) { O_NONBLOCK, P9_DOTL_NONBLOCK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) { O_DSYNC, P9_DOTL_DSYNC },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) { FASYNC, P9_DOTL_FASYNC },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) { O_DIRECT, P9_DOTL_DIRECT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) { O_LARGEFILE, P9_DOTL_LARGEFILE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) { O_DIRECTORY, P9_DOTL_DIRECTORY },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) { O_NOFOLLOW, P9_DOTL_NOFOLLOW },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) { O_NOATIME, P9_DOTL_NOATIME },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) { O_CLOEXEC, P9_DOTL_CLOEXEC },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) { O_SYNC, P9_DOTL_SYNC},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) for (i = 0; i < ARRAY_SIZE(dotl_oflag_map); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (flags & dotl_oflag_map[i].open_flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) rflags |= dotl_oflag_map[i].dotl_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return rflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * v9fs_open_to_dotl_flags- convert Linux specific open flags to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * plan 9 open flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * @flags: flags to convert
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) int v9fs_open_to_dotl_flags(int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) int rflags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * We have same bits for P9_DOTL_READONLY, P9_DOTL_WRONLY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * and P9_DOTL_NOACCESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) rflags |= flags & O_ACCMODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) rflags |= v9fs_mapped_dotl_flags(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return rflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * v9fs_vfs_create_dotl - VFS hook to create files for 9P2000.L protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * @dir: directory inode that is being created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * @dentry: dentry that is being deleted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * @omode: create permissions
^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) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, umode_t omode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) bool excl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return v9fs_vfs_mknod_dotl(dir, dentry, omode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct file *file, unsigned flags, umode_t omode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) kgid_t gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) umode_t mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) const unsigned char *name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct p9_qid qid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct p9_fid *fid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct v9fs_inode *v9inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct p9_fid *dfid, *ofid, *inode_fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct posix_acl *pacl = NULL, *dacl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct dentry *res = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (d_in_lookup(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) res = v9fs_vfs_lookup(dir, dentry, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (IS_ERR(res))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return PTR_ERR(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) dentry = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /* Only creates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (!(flags & O_CREAT) || d_really_is_positive(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return finish_no_open(file, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) v9ses = v9fs_inode2v9ses(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) name = dentry->d_name.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) p9_debug(P9_DEBUG_VFS, "name:%s flags:0x%x mode:0x%hx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) name, flags, omode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) dfid = v9fs_parent_fid(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (IS_ERR(dfid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) err = PTR_ERR(dfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /* clone a fid to use for creation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) ofid = clone_fid(dfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (IS_ERR(ofid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) err = PTR_ERR(ofid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) gid = v9fs_get_fsgid_for_create(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) mode = omode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) /* Update mode based on ACL value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) p9_debug(P9_DEBUG_VFS, "Failed to get acl values in creat %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) err = p9_client_create_dotl(ofid, name, v9fs_open_to_dotl_flags(flags),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) mode, gid, &qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) p9_debug(P9_DEBUG_VFS, "p9_client_open_dotl failed in creat %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) v9fs_invalidate_inode_attr(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) /* instantiate inode and assign the unopened fid to the dentry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) fid = p9_client_walk(dfid, 1, &name, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) if (IS_ERR(fid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) err = PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) fid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) err = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) /* Now set the ACL based on the default value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) v9fs_set_create_acl(inode, fid, dacl, pacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) v9fs_fid_add(dentry, fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) v9inode = V9FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) mutex_lock(&v9inode->v_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if ((v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) !v9inode->writeback_fid &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) ((flags & O_ACCMODE) != O_RDONLY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * clone a fid and add it to writeback_fid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * we do it during open time instead of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * page dirty time via write_begin/page_mkwrite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * because we want write after unlink usecase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * to work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) inode_fid = v9fs_writeback_fid(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) if (IS_ERR(inode_fid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) err = PTR_ERR(inode_fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) mutex_unlock(&v9inode->v_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) goto err_clunk_old_fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) v9inode->writeback_fid = (void *) inode_fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) mutex_unlock(&v9inode->v_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) /* Since we are opening a file, assign the open fid to the file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) err = finish_open(file, dentry, generic_file_open);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) goto err_clunk_old_fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) file->private_data = ofid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) v9fs_cache_inode_set_cookie(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) file->f_mode |= FMODE_CREATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) v9fs_put_acl(dacl, pacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) dput(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) if (fid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) p9_client_clunk(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) err_clunk_old_fid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (ofid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) p9_client_clunk(ofid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * @dir: inode that is being unlinked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * @dentry: dentry that is being unlinked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * @omode: mode for new directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static int v9fs_vfs_mkdir_dotl(struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) struct dentry *dentry, umode_t omode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) struct p9_fid *fid = NULL, *dfid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) kgid_t gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) const unsigned char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) umode_t mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) struct p9_qid qid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) struct posix_acl *dacl = NULL, *pacl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) p9_debug(P9_DEBUG_VFS, "name %pd\n", dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) v9ses = v9fs_inode2v9ses(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) omode |= S_IFDIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (dir->i_mode & S_ISGID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) omode |= S_ISGID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) dfid = v9fs_parent_fid(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) if (IS_ERR(dfid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) err = PTR_ERR(dfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) dfid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) gid = v9fs_get_fsgid_for_create(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) mode = omode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) /* Update mode based on ACL value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) p9_debug(P9_DEBUG_VFS, "Failed to get acl values in mkdir %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) name = dentry->d_name.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) fid = p9_client_walk(dfid, 1, &name, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) if (IS_ERR(fid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) err = PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) fid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) /* instantiate inode and assign the unopened fid to the dentry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) err = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) v9fs_fid_add(dentry, fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) v9fs_set_create_acl(inode, fid, dacl, pacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) fid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) * Not in cached mode. No need to populate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) * inode with stat. We need to get an inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) * so that we can set the acl with dentry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) inode = v9fs_get_inode(dir->i_sb, mode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) err = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) v9fs_set_create_acl(inode, fid, dacl, pacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) inc_nlink(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) v9fs_invalidate_inode_attr(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) if (fid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) p9_client_clunk(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) v9fs_put_acl(dacl, pacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) v9fs_vfs_getattr_dotl(const struct path *path, struct kstat *stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) u32 request_mask, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) struct dentry *dentry = path->dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) struct p9_fid *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) struct p9_stat_dotl *st;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) p9_debug(P9_DEBUG_VFS, "dentry: %p\n", dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) v9ses = v9fs_dentry2v9ses(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) generic_fillattr(d_inode(dentry), stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) fid = v9fs_fid_lookup(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) if (IS_ERR(fid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) return PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) /* Ask for all the fields in stat structure. Server will return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) * whatever it supports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) if (IS_ERR(st))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) return PTR_ERR(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) v9fs_stat2inode_dotl(st, d_inode(dentry), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) generic_fillattr(d_inode(dentry), stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) /* Change block size to what the server returned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) stat->blksize = st->st_blksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) kfree(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) return 0;
^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) * Attribute flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) #define P9_ATTR_MODE (1 << 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) #define P9_ATTR_UID (1 << 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) #define P9_ATTR_GID (1 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) #define P9_ATTR_SIZE (1 << 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) #define P9_ATTR_ATIME (1 << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) #define P9_ATTR_MTIME (1 << 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) #define P9_ATTR_CTIME (1 << 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) #define P9_ATTR_ATIME_SET (1 << 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) #define P9_ATTR_MTIME_SET (1 << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) struct dotl_iattr_map {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) int iattr_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) int p9_iattr_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) static int v9fs_mapped_iattr_valid(int iattr_valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) int p9_iattr_valid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) struct dotl_iattr_map dotl_iattr_map[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) { ATTR_MODE, P9_ATTR_MODE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) { ATTR_UID, P9_ATTR_UID },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) { ATTR_GID, P9_ATTR_GID },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) { ATTR_SIZE, P9_ATTR_SIZE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) { ATTR_ATIME, P9_ATTR_ATIME },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) { ATTR_MTIME, P9_ATTR_MTIME },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) { ATTR_CTIME, P9_ATTR_CTIME },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) { ATTR_ATIME_SET, P9_ATTR_ATIME_SET },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) { ATTR_MTIME_SET, P9_ATTR_MTIME_SET },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) for (i = 0; i < ARRAY_SIZE(dotl_iattr_map); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) if (iattr_valid & dotl_iattr_map[i].iattr_valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) p9_iattr_valid |= dotl_iattr_map[i].p9_iattr_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) return p9_iattr_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) * v9fs_vfs_setattr_dotl - set file metadata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) * @dentry: file whose metadata to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) * @iattr: metadata assignment structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) struct p9_fid *fid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) struct p9_iattr_dotl p9attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) .uid = INVALID_UID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) .gid = INVALID_GID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) p9_debug(P9_DEBUG_VFS, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) retval = setattr_prepare(dentry, iattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) p9attr.valid = v9fs_mapped_iattr_valid(iattr->ia_valid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) if (iattr->ia_valid & ATTR_MODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) p9attr.mode = iattr->ia_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) if (iattr->ia_valid & ATTR_UID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) p9attr.uid = iattr->ia_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) if (iattr->ia_valid & ATTR_GID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) p9attr.gid = iattr->ia_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) if (iattr->ia_valid & ATTR_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) p9attr.size = iattr->ia_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) if (iattr->ia_valid & ATTR_ATIME_SET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) p9attr.atime_sec = iattr->ia_atime.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) if (iattr->ia_valid & ATTR_MTIME_SET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) if (iattr->ia_valid & ATTR_FILE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) fid = iattr->ia_file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) WARN_ON(!fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) if (!fid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) fid = v9fs_fid_lookup(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (IS_ERR(fid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) return PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) /* Write all dirty data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) if (S_ISREG(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) filemap_write_and_wait(inode->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) retval = p9_client_setattr(fid, &p9attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) if ((iattr->ia_valid & ATTR_SIZE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) iattr->ia_size != i_size_read(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) truncate_setsize(inode, iattr->ia_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) v9fs_invalidate_inode_attr(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) setattr_copy(inode, iattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) if (iattr->ia_valid & ATTR_MODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) /* We also want to update ACL when we update mode bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) retval = v9fs_acl_chmod(inode, fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) * v9fs_stat2inode_dotl - populate an inode structure with stat info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) * @stat: stat structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) * @inode: inode to populate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) * @flags: ctrl flags (e.g. V9FS_STAT2INODE_KEEP_ISIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) umode_t mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) struct v9fs_inode *v9inode = V9FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) inode->i_atime.tv_sec = stat->st_atime_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) inode->i_atime.tv_nsec = stat->st_atime_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) inode->i_mtime.tv_sec = stat->st_mtime_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) inode->i_ctime.tv_sec = stat->st_ctime_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) inode->i_uid = stat->st_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) inode->i_gid = stat->st_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) set_nlink(inode, stat->st_nlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) mode = stat->st_mode & S_IALLUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) mode |= inode->i_mode & ~S_IALLUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) inode->i_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) if (!(flags & V9FS_STAT2INODE_KEEP_ISIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) v9fs_i_size_write(inode, stat->st_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) inode->i_blocks = stat->st_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) if (stat->st_result_mask & P9_STATS_ATIME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) inode->i_atime.tv_sec = stat->st_atime_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) inode->i_atime.tv_nsec = stat->st_atime_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) if (stat->st_result_mask & P9_STATS_MTIME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) inode->i_mtime.tv_sec = stat->st_mtime_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) if (stat->st_result_mask & P9_STATS_CTIME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) inode->i_ctime.tv_sec = stat->st_ctime_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) if (stat->st_result_mask & P9_STATS_UID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) inode->i_uid = stat->st_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) if (stat->st_result_mask & P9_STATS_GID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) inode->i_gid = stat->st_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) if (stat->st_result_mask & P9_STATS_NLINK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) set_nlink(inode, stat->st_nlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) if (stat->st_result_mask & P9_STATS_MODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) inode->i_mode = stat->st_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) if ((S_ISBLK(inode->i_mode)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) (S_ISCHR(inode->i_mode)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) init_special_inode(inode, inode->i_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) inode->i_rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) if (stat->st_result_mask & P9_STATS_RDEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) inode->i_rdev = new_decode_dev(stat->st_rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) if (!(flags & V9FS_STAT2INODE_KEEP_ISIZE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) stat->st_result_mask & P9_STATS_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) v9fs_i_size_write(inode, stat->st_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) if (stat->st_result_mask & P9_STATS_BLOCKS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) inode->i_blocks = stat->st_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) if (stat->st_result_mask & P9_STATS_GEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) inode->i_generation = stat->st_gen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) * because the inode structure does not have fields for them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) v9inode->cache_validity &= ~V9FS_INO_INVALID_ATTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) const char *symname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) kgid_t gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) const unsigned char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) struct p9_qid qid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) struct p9_fid *dfid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) struct p9_fid *fid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) name = dentry->d_name.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) p9_debug(P9_DEBUG_VFS, "%lu,%s,%s\n", dir->i_ino, name, symname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) v9ses = v9fs_inode2v9ses(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) dfid = v9fs_parent_fid(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) if (IS_ERR(dfid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) err = PTR_ERR(dfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) gid = v9fs_get_fsgid_for_create(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) err = p9_client_symlink(dfid, name, symname, gid, &qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) p9_debug(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) v9fs_invalidate_inode_attr(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) /* Now walk from the parent so we can get an unopened fid. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) fid = p9_client_walk(dfid, 1, &name, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) if (IS_ERR(fid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) err = PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) fid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) goto error;
^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) /* instantiate inode and assign the unopened fid to dentry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) err = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) v9fs_fid_add(dentry, fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) fid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) /* Not in cached mode. No need to populate inode with stat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) inode = v9fs_get_inode(dir->i_sb, S_IFLNK, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) err = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) if (fid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) p9_client_clunk(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) * v9fs_vfs_link_dotl - create a hardlink for dotl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) * @old_dentry: dentry for file to link to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) * @dir: inode destination for new link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) * @dentry: dentry for link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) struct p9_fid *dfid, *oldfid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) p9_debug(P9_DEBUG_VFS, "dir ino: %lu, old_name: %pd, new_name: %pd\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) dir->i_ino, old_dentry, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) v9ses = v9fs_inode2v9ses(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) dfid = v9fs_parent_fid(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) if (IS_ERR(dfid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) return PTR_ERR(dfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) oldfid = v9fs_fid_lookup(old_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) if (IS_ERR(oldfid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) return PTR_ERR(oldfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) err = p9_client_link(dfid, oldfid, dentry->d_name.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) p9_debug(P9_DEBUG_VFS, "p9_client_link failed %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) v9fs_invalidate_inode_attr(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) /* Get the latest stat info from server. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) struct p9_fid *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) fid = v9fs_fid_lookup(old_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) if (IS_ERR(fid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) return PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) v9fs_refresh_inode_dotl(fid, d_inode(old_dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) ihold(d_inode(old_dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) d_instantiate(dentry, d_inode(old_dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) * v9fs_vfs_mknod_dotl - create a special file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) * @dir: inode destination for new link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) * @dentry: dentry for file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) * @omode: mode for creation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) * @rdev: device associated with special file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, umode_t omode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) dev_t rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) kgid_t gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) const unsigned char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) umode_t mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) struct p9_fid *fid = NULL, *dfid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) struct p9_qid qid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) struct posix_acl *dacl = NULL, *pacl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) p9_debug(P9_DEBUG_VFS, " %lu,%pd mode: %hx MAJOR: %u MINOR: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) dir->i_ino, dentry, omode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) MAJOR(rdev), MINOR(rdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) v9ses = v9fs_inode2v9ses(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) dfid = v9fs_parent_fid(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) if (IS_ERR(dfid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) err = PTR_ERR(dfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) dfid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) gid = v9fs_get_fsgid_for_create(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) mode = omode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) /* Update mode based on ACL value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) p9_debug(P9_DEBUG_VFS, "Failed to get acl values in mknod %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) name = dentry->d_name.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) v9fs_invalidate_inode_attr(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) fid = p9_client_walk(dfid, 1, &name, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) if (IS_ERR(fid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) err = PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) fid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) goto error;
^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) /* instantiate inode and assign the unopened fid to the dentry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) err = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) v9fs_set_create_acl(inode, fid, dacl, pacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) v9fs_fid_add(dentry, fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) fid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) * Not in cached mode. No need to populate inode with stat.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) * socket syscall returns a fd, so we need instantiate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) inode = v9fs_get_inode(dir->i_sb, mode, rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) err = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) v9fs_set_create_acl(inode, fid, dacl, pacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) if (fid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) p9_client_clunk(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) v9fs_put_acl(dacl, pacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) * v9fs_vfs_get_link_dotl - follow a symlink path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) * @dentry: dentry for symlink
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) * @inode: inode for symlink
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) * @done: destructor for return value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) static const char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) v9fs_vfs_get_link_dotl(struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) struct delayed_call *done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) struct p9_fid *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) char *target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) if (!dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) return ERR_PTR(-ECHILD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) p9_debug(P9_DEBUG_VFS, "%pd\n", dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) fid = v9fs_fid_lookup(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) if (IS_ERR(fid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) return ERR_CAST(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) retval = p9_client_readlink(fid, &target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) return ERR_PTR(retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) set_delayed_call(done, kfree_link, target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) return target;
^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) int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) struct p9_stat_dotl *st;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) unsigned int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) v9ses = v9fs_inode2v9ses(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) if (IS_ERR(st))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) return PTR_ERR(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) * Don't update inode if the file type is different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) if (inode_wrong_type(inode, st->st_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) * We don't want to refresh inode->i_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) * because we may have cached data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) flags = (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) V9FS_STAT2INODE_KEEP_ISIZE : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) v9fs_stat2inode_dotl(st, inode, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) kfree(st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) const struct inode_operations v9fs_dir_inode_operations_dotl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) .create = v9fs_vfs_create_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) .atomic_open = v9fs_vfs_atomic_open_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) .lookup = v9fs_vfs_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) .link = v9fs_vfs_link_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) .symlink = v9fs_vfs_symlink_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) .unlink = v9fs_vfs_unlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) .mkdir = v9fs_vfs_mkdir_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) .rmdir = v9fs_vfs_rmdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) .mknod = v9fs_vfs_mknod_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) .rename = v9fs_vfs_rename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) .getattr = v9fs_vfs_getattr_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) .setattr = v9fs_vfs_setattr_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) .listxattr = v9fs_listxattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) .get_acl = v9fs_iop_get_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) const struct inode_operations v9fs_file_inode_operations_dotl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) .getattr = v9fs_vfs_getattr_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) .setattr = v9fs_vfs_setattr_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) .listxattr = v9fs_listxattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) .get_acl = v9fs_iop_get_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) const struct inode_operations v9fs_symlink_inode_operations_dotl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) .get_link = v9fs_vfs_get_link_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) .getattr = v9fs_vfs_getattr_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) .setattr = v9fs_vfs_setattr_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) .listxattr = v9fs_listxattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) };