^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) * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/cred.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/xattr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/posix_acl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/gfs2_ondisk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/crc32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/iomap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/fiemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "gfs2.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "incore.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "acl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "bmap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "dir.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "xattr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include "glock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include "inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include "meta_io.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include "quota.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include "rgrp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include "trans.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include "util.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include "super.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include "glops.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static int iget_test(struct inode *inode, void *opaque)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) u64 no_addr = *(u64 *)opaque;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return GFS2_I(inode)->i_no_addr == no_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static int iget_set(struct inode *inode, void *opaque)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) u64 no_addr = *(u64 *)opaque;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) GFS2_I(inode)->i_no_addr = no_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) inode->i_ino = no_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static struct inode *gfs2_iget(struct super_block *sb, u64 no_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) repeat:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) inode = iget5_locked(sb, no_addr, iget_test, iget_set, &no_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (is_bad_inode(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) goto repeat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * gfs2_set_iop - Sets inode operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * @inode: The inode with correct i_mode filled in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * GFS2 lookup code fills in vfs inode contents based on info obtained
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * from directory entry inside gfs2_inode_lookup().
^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) static void gfs2_set_iop(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct gfs2_sbd *sdp = GFS2_SB(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) umode_t mode = inode->i_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (S_ISREG(mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) inode->i_op = &gfs2_file_iops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (gfs2_localflocks(sdp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) inode->i_fop = &gfs2_file_fops_nolock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) inode->i_fop = &gfs2_file_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) } else if (S_ISDIR(mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) inode->i_op = &gfs2_dir_iops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (gfs2_localflocks(sdp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) inode->i_fop = &gfs2_dir_fops_nolock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) inode->i_fop = &gfs2_dir_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) } else if (S_ISLNK(mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) inode->i_op = &gfs2_symlink_iops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) inode->i_op = &gfs2_file_iops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) init_special_inode(inode, inode->i_mode, inode->i_rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^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) * gfs2_inode_lookup - Lookup an inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * @sb: The super block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * @type: The type of the inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * @no_addr: The inode number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * @no_formal_ino: The inode generation number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * @blktype: Requested block type (GFS2_BLKST_DINODE or GFS2_BLKST_UNLINKED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * GFS2_BLKST_FREE to indicate not to verify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * If @type is DT_UNKNOWN, the inode type is fetched from disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * If @blktype is anything other than GFS2_BLKST_FREE (which is used as a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * placeholder because it doesn't otherwise make sense), the on-disk block type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * is verified to be @blktype.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * When @no_formal_ino is non-zero, this function will return ERR_PTR(-ESTALE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * if it detects that @no_formal_ino doesn't match the actual inode generation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * number. However, it doesn't always know unless @type is DT_UNKNOWN.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * Returns: A VFS inode, or an error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) u64 no_addr, u64 no_formal_ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) unsigned int blktype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct gfs2_inode *ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct gfs2_glock *io_gl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct gfs2_holder i_gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) gfs2_holder_mark_uninitialized(&i_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) inode = gfs2_iget(sb, no_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) ip = GFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (inode->i_state & I_NEW) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct gfs2_sbd *sdp = GFS2_SB(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (unlikely(error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) flush_delayed_work(&ip->i_gl->gl_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) error = gfs2_glock_get(sdp, no_addr, &gfs2_iopen_glops, CREATE, &io_gl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (unlikely(error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (blktype != GFS2_BLKST_UNLINKED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) gfs2_cancel_delete_work(io_gl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (type == DT_UNKNOWN || blktype != GFS2_BLKST_FREE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * The GL_SKIP flag indicates to skip reading the inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * block. We read the inode with gfs2_inode_refresh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * after possibly checking the block type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) GL_SKIP, &i_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) error = -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (no_formal_ino &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) gfs2_inode_already_deleted(ip->i_gl, no_formal_ino))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (blktype != GFS2_BLKST_FREE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) error = gfs2_check_blk_type(sdp, no_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) blktype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^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) glock_set_object(ip->i_gl, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) set_bit(GIF_INVALID, &ip->i_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (unlikely(error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) glock_set_object(ip->i_iopen_gh.gh_gl, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) gfs2_glock_put(io_gl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) io_gl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /* Lowest possible timestamp; will be overwritten in gfs2_dinode_in. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) inode->i_atime.tv_sec = 1LL << (8 * sizeof(inode->i_atime.tv_sec) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) inode->i_atime.tv_nsec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (type == DT_UNKNOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /* Inode glock must be locked already */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) error = gfs2_inode_refresh(GFS2_I(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) ip->i_no_formal_ino = no_formal_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) inode->i_mode = DT2IF(type);
^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) if (gfs2_holder_initialized(&i_gh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) gfs2_glock_dq_uninit(&i_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) gfs2_set_iop(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (no_formal_ino && ip->i_no_formal_ino &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) no_formal_ino != ip->i_no_formal_ino) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) error = -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (inode->i_state & I_NEW)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return ERR_PTR(error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (inode->i_state & I_NEW)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) unlock_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (io_gl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) gfs2_glock_put(io_gl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (gfs2_holder_initialized(&i_gh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) gfs2_glock_dq_uninit(&i_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) iget_failed(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return ERR_PTR(error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * gfs2_lookup_by_inum - look up an inode by inode number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * @sdp: The super block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * @no_addr: The inode number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * @no_formal_ino: The inode generation number (0 for any)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * @blktype: Requested block type (see gfs2_inode_lookup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct inode *gfs2_lookup_by_inum(struct gfs2_sbd *sdp, u64 no_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) u64 no_formal_ino, unsigned int blktype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct super_block *sb = sdp->sd_vfs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) inode = gfs2_inode_lookup(sb, DT_UNKNOWN, no_addr, no_formal_ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) blktype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (no_formal_ino) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (GFS2_I(inode)->i_diskflags & GFS2_DIF_SYSTEM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) goto fail_iput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) fail_iput:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return ERR_PTR(error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) struct inode *gfs2_lookup_simple(struct inode *dip, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) struct qstr qstr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) gfs2_str2qstr(&qstr, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) inode = gfs2_lookupi(dip, &qstr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /* gfs2_lookupi has inconsistent callers: vfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * related routines expect NULL for no entry found,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * gfs2_lookup_simple callers expect ENOENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * and do not check for NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) if (inode == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * gfs2_lookupi - Look up a filename in a directory and return its inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * @d_gh: An initialized holder for the directory glock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * @name: The name of the inode to look for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * @is_root: If 1, ignore the caller's permissions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * @i_gh: An uninitialized holder for the new inode glock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) * This can be called via the VFS filldir function when NFS is doing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) * a readdirplus and the inode which its intending to stat isn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) * already in cache. In this case we must not take the directory glock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) * again, since the readdir call will have already taken that lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) int is_root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) struct super_block *sb = dir->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) struct gfs2_inode *dip = GFS2_I(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) struct gfs2_holder d_gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) struct inode *inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) gfs2_holder_mark_uninitialized(&d_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) if (!name->len || name->len > GFS2_FNAMESIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) return ERR_PTR(-ENAMETOOLONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if ((name->len == 1 && memcmp(name->name, ".", 1) == 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) (name->len == 2 && memcmp(name->name, "..", 2) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) dir == d_inode(sb->s_root))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) igrab(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (gfs2_glock_is_locked_by_me(dip->i_gl) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) return ERR_PTR(error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (!is_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) error = gfs2_permission(dir, MAY_EXEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) inode = gfs2_dir_search(dir, name, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) error = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) if (gfs2_holder_initialized(&d_gh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) gfs2_glock_dq_uninit(&d_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) if (error == -ENOENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return inode ? inode : ERR_PTR(error);
^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) * create_ok - OK to create a new on-disk inode here?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) * @dip: Directory in which dinode is to be created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * @name: Name of new dinode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * @mode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) static int create_ok(struct gfs2_inode *dip, const struct qstr *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /* Don't create entries in an unlinked directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) if (!dip->i_inode.i_nlink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (dip->i_entries == (u32)-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) return -EFBIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) if (S_ISDIR(mode) && dip->i_inode.i_nlink == (u32)-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) return -EMLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) return 0;
^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) static void munge_mode_uid_gid(const struct gfs2_inode *dip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) if (GFS2_SB(&dip->i_inode)->sd_args.ar_suiddir &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) (dip->i_inode.i_mode & S_ISUID) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) !uid_eq(dip->i_inode.i_uid, GLOBAL_ROOT_UID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) inode->i_mode |= S_ISUID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) else if (!uid_eq(dip->i_inode.i_uid, current_fsuid()))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) inode->i_mode &= ~07111;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) inode->i_uid = dip->i_inode.i_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) inode->i_uid = current_fsuid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) if (dip->i_inode.i_mode & S_ISGID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) inode->i_mode |= S_ISGID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) inode->i_gid = dip->i_inode.i_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) inode->i_gid = current_fsgid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) static int alloc_dinode(struct gfs2_inode *ip, u32 flags, unsigned *dblocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) struct gfs2_alloc_parms ap = { .target = *dblocks, .aflags = flags, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) error = gfs2_quota_lock_check(ip, &ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) error = gfs2_inplace_reserve(ip, &ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) goto out_quota;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) error = gfs2_trans_begin(sdp, (*dblocks * RES_RG_BIT) + RES_STATFS + RES_QUOTA, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) goto out_ipreserv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) error = gfs2_alloc_blocks(ip, &ip->i_no_addr, dblocks, 1, &ip->i_generation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) ip->i_no_formal_ino = ip->i_generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) ip->i_inode.i_ino = ip->i_no_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) ip->i_goal = ip->i_no_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) gfs2_trans_end(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) out_ipreserv:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) gfs2_inplace_release(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) out_quota:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) gfs2_quota_unlock(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) static void gfs2_init_dir(struct buffer_head *dibh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) const struct gfs2_inode *parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) gfs2_qstr2dirent(&gfs2_qdot, GFS2_DIRENT_SIZE(gfs2_qdot.len), dent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) dent->de_inum = di->di_num; /* already GFS2 endian */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) dent->de_type = cpu_to_be16(DT_DIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) gfs2_qstr2dirent(&gfs2_qdotdot, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) gfs2_inum_out(parent, dent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) dent->de_type = cpu_to_be16(DT_DIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) * gfs2_init_xattr - Initialise an xattr block for a new inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) * @ip: The inode in question
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) * This sets up an empty xattr block for a new inode, ready to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) * take any ACLs, LSM xattrs, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) static void gfs2_init_xattr(struct gfs2_inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) struct gfs2_ea_header *ea;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) bh = gfs2_meta_new(ip->i_gl, ip->i_eattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) gfs2_trans_add_meta(ip->i_gl, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) gfs2_metatype_set(bh, GFS2_METATYPE_EA, GFS2_FORMAT_EA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) ea = GFS2_EA_BH2FIRST(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) ea->ea_rec_len = cpu_to_be32(sdp->sd_jbsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) ea->ea_type = GFS2_EATYPE_UNUSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) ea->ea_flags = GFS2_EAFLAG_LAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) * init_dinode - Fill in a new dinode structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * @dip: The directory this inode is being created in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) * @ip: The inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) * @symname: The symlink destination (if a symlink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * @bhp: The buffer head (returned to caller)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) static void init_dinode(struct gfs2_inode *dip, struct gfs2_inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) const char *symname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) struct gfs2_dinode *di;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) struct buffer_head *dibh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) dibh = gfs2_meta_new(ip->i_gl, ip->i_no_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) gfs2_trans_add_meta(ip->i_gl, dibh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) di = (struct gfs2_dinode *)dibh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) gfs2_dinode_out(ip, di);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) di->di_major = cpu_to_be32(MAJOR(ip->i_inode.i_rdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) di->di_minor = cpu_to_be32(MINOR(ip->i_inode.i_rdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) di->__pad1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) di->__pad2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) di->__pad3 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) memset(&di->__pad4, 0, sizeof(di->__pad4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) memset(&di->di_reserved, 0, sizeof(di->di_reserved));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) switch(ip->i_inode.i_mode & S_IFMT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) case S_IFDIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) gfs2_init_dir(dibh, dip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) case S_IFLNK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname, ip->i_inode.i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) break;
^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) set_buffer_uptodate(dibh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) brelse(dibh);
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) * gfs2_trans_da_blocks - Calculate number of blocks to link inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) * @dip: The directory we are linking into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) * @da: The dir add information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) * @nr_inodes: The number of inodes involved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) * This calculate the number of blocks we need to reserve in a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) * transaction to link @nr_inodes into a directory. In most cases
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) * @nr_inodes will be 2 (the directory plus the inode being linked in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) * but in case of rename, 4 may be required.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) * Returns: Number of blocks
^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) static unsigned gfs2_trans_da_blks(const struct gfs2_inode *dip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) const struct gfs2_diradd *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) unsigned nr_inodes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) return da->nr_blocks + gfs2_rg_blocks(dip, da->nr_blocks) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) (nr_inodes * RES_DINODE) + RES_QUOTA + RES_STATFS;
^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) static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) struct gfs2_inode *ip, struct gfs2_diradd *da)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) struct gfs2_alloc_parms ap = { .target = da->nr_blocks, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) if (da->nr_blocks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) error = gfs2_quota_lock_check(dip, &ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) goto fail_quota_locks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) error = gfs2_inplace_reserve(dip, &ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) goto fail_quota_locks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) error = gfs2_trans_begin(sdp, gfs2_trans_da_blks(dip, da, 2), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) goto fail_ipreserv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) error = gfs2_trans_begin(sdp, RES_LEAF + 2 * RES_DINODE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) goto fail_quota_locks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) error = gfs2_dir_add(&dip->i_inode, name, ip, da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) gfs2_trans_end(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) fail_ipreserv:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) gfs2_inplace_release(dip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) fail_quota_locks:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) gfs2_quota_unlock(dip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) static int gfs2_initxattrs(struct inode *inode, const struct xattr *xattr_array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) void *fs_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) const struct xattr *xattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) for (xattr = xattr_array; xattr->name != NULL; xattr++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) err = __gfs2_xattr_set(inode, xattr->name, xattr->value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) xattr->value_len, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) GFS2_EATYPE_SECURITY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) * gfs2_create_inode - Create a new inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) * @dir: The parent directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) * @dentry: The new dentry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) * @file: If non-NULL, the file which is being opened
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) * @mode: The permissions on the new inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) * @dev: For device nodes, this is the device number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) * @symname: For symlinks, this is the link destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) * @size: The initial size of the inode (ignored for directories)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) * Returns: 0 on success, or error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) umode_t mode, dev_t dev, const char *symname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) unsigned int size, int excl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) const struct qstr *name = &dentry->d_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) struct posix_acl *default_acl, *acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) struct gfs2_holder ghs[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) struct inode *inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) struct gfs2_inode *dip = GFS2_I(dir), *ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) struct gfs2_glock *io_gl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) int error, free_vfs_inode = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) u32 aflags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) unsigned blocks = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) struct gfs2_diradd da = { .bh = NULL, .save_loc = 1, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) if (!name->len || name->len > GFS2_FNAMESIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) return -ENAMETOOLONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) error = gfs2_qa_get(dip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) error = gfs2_rindex_update(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) error = gfs2_glock_nq_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) gfs2_holder_mark_uninitialized(ghs + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) error = create_ok(dip, name, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) goto fail_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) inode = gfs2_dir_search(dir, &dentry->d_name, !S_ISREG(mode) || excl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) error = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) if (!IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) if (S_ISDIR(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) inode = ERR_PTR(-EISDIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) goto fail_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) if (file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) if (S_ISREG(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) error = finish_open(file, dentry, gfs2_open_common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) error = finish_no_open(file, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) gfs2_glock_dq_uninit(ghs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) } else if (error != -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) goto fail_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) error = gfs2_diradd_alloc_required(dir, name, &da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) goto fail_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) inode = new_inode(sdp->sd_vfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) goto fail_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) error = posix_acl_create(dir, &mode, &default_acl, &acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) goto fail_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) ip = GFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) error = gfs2_qa_get(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) goto fail_free_acls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) inode->i_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) set_nlink(inode, S_ISDIR(mode) ? 2 : 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) inode->i_rdev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) inode->i_size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) munge_mode_uid_gid(dip, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) check_and_update_goal(dip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) ip->i_goal = dip->i_goal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) ip->i_diskflags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) ip->i_eattr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) ip->i_height = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) ip->i_depth = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) ip->i_entries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) ip->i_no_addr = 0; /* Temporarily zero until real addr is assigned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) switch(mode & S_IFMT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) case S_IFREG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) if ((dip->i_diskflags & GFS2_DIF_INHERIT_JDATA) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) gfs2_tune_get(sdp, gt_new_files_jdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) ip->i_diskflags |= GFS2_DIF_JDATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) gfs2_set_aops(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) case S_IFDIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) ip->i_diskflags |= (dip->i_diskflags & GFS2_DIF_INHERIT_JDATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) ip->i_diskflags |= GFS2_DIF_JDATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) ip->i_entries = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) /* Force SYSTEM flag on all files and subdirs of a SYSTEM directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) if (dip->i_diskflags & GFS2_DIF_SYSTEM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) ip->i_diskflags |= GFS2_DIF_SYSTEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) gfs2_set_inode_flags(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) if ((GFS2_I(d_inode(sdp->sd_root_dir)) == dip) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) (dip->i_diskflags & GFS2_DIF_TOPDIR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) aflags |= GFS2_AF_ORLOV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) if (default_acl || acl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) blocks++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) error = alloc_dinode(ip, aflags, &blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) goto fail_free_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) gfs2_set_inode_blocks(inode, blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) goto fail_free_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) flush_delayed_work(&ip->i_gl->gl_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) glock_set_object(ip->i_gl, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_iopen_glops, CREATE, &io_gl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) goto fail_free_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) gfs2_cancel_delete_work(io_gl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) glock_set_object(io_gl, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_SKIP, ghs + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) goto fail_gunlock2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) error = gfs2_trans_begin(sdp, blocks, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) goto fail_gunlock2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) if (blocks > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) ip->i_eattr = ip->i_no_addr + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) gfs2_init_xattr(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) init_dinode(dip, ip, symname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) gfs2_trans_end(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) BUG_ON(test_and_set_bit(GLF_INODE_CREATING, &io_gl->gl_flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) goto fail_gunlock2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) gfs2_set_iop(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) insert_inode_hash(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) free_vfs_inode = 0; /* After this point, the inode is no longer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) considered free. Any failures need to undo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) the gfs2 structures. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) if (default_acl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) error = __gfs2_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) goto fail_gunlock3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) posix_acl_release(default_acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) default_acl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) if (acl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) error = __gfs2_set_acl(inode, acl, ACL_TYPE_ACCESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) goto fail_gunlock3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) posix_acl_release(acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) acl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) error = security_inode_init_security(&ip->i_inode, &dip->i_inode, name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) &gfs2_initxattrs, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) goto fail_gunlock3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) error = link_dinode(dip, name, ip, &da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) goto fail_gunlock3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) /* After instantiate, errors should result in evict which will destroy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) * both inode and iopen glocks properly. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) if (file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) file->f_mode |= FMODE_CREATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) error = finish_open(file, dentry, gfs2_open_common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) gfs2_glock_dq_uninit(ghs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) gfs2_qa_put(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) gfs2_glock_dq_uninit(ghs + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) clear_bit(GLF_INODE_CREATING, &io_gl->gl_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) gfs2_glock_put(io_gl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) gfs2_qa_put(dip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) fail_gunlock3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) glock_clear_object(io_gl, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) gfs2_glock_dq_uninit(&ip->i_iopen_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) fail_gunlock2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) clear_bit(GLF_INODE_CREATING, &io_gl->gl_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) glock_clear_object(io_gl, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) gfs2_glock_put(io_gl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) fail_free_inode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) if (ip->i_gl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) glock_clear_object(ip->i_gl, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) if (free_vfs_inode) /* else evict will do the put for us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) gfs2_glock_put(ip->i_gl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) gfs2_rs_delete(ip, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) gfs2_qa_put(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) fail_free_acls:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) posix_acl_release(default_acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) posix_acl_release(acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) fail_gunlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) gfs2_dir_no_add(&da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) gfs2_glock_dq_uninit(ghs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) if (!IS_ERR_OR_NULL(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) clear_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) if (!free_vfs_inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) set_bit(free_vfs_inode ? GIF_FREE_VFS_INODE : GIF_ALLOC_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) &GFS2_I(inode)->i_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) if (gfs2_holder_initialized(ghs + 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) gfs2_glock_dq_uninit(ghs + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) gfs2_qa_put(dip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) * gfs2_create - Create a file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) * @dir: The directory in which to create the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) * @dentry: The dentry of the new file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) * @mode: The mode of the new file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) static int gfs2_create(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) umode_t mode, bool excl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) return gfs2_create_inode(dir, dentry, NULL, S_IFREG | mode, 0, NULL, 0, excl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) * __gfs2_lookup - Look up a filename in a directory and return its inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) * @dir: The directory inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) * @dentry: The dentry of the new inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) * @file: File to be opened
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) static struct dentry *__gfs2_lookup(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) struct dentry *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) struct gfs2_holder gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) struct gfs2_glock *gl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) inode = gfs2_lookupi(dir, &dentry->d_name, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) if (inode == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) d_add(dentry, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) return ERR_CAST(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) gl = GFS2_I(inode)->i_gl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) error = gfs2_glock_nq_init(gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) return ERR_PTR(error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) d = d_splice_alias(inode, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) if (IS_ERR(d)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) gfs2_glock_dq_uninit(&gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) return d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) if (file && S_ISREG(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) error = finish_open(file, dentry, gfs2_open_common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) gfs2_glock_dq_uninit(&gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) dput(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) return ERR_PTR(error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) return d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) unsigned flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) return __gfs2_lookup(dir, dentry, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) * gfs2_link - Link to a file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) * @old_dentry: The inode to link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) * @dir: Add link to this directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) * @dentry: The name of the link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) * Link the inode in "old_dentry" into the directory "dir" with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) * name in "dentry".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) struct gfs2_inode *dip = GFS2_I(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) struct gfs2_sbd *sdp = GFS2_SB(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) struct inode *inode = d_inode(old_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) struct gfs2_inode *ip = GFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) struct gfs2_holder ghs[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) struct buffer_head *dibh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) struct gfs2_diradd da = { .bh = NULL, .save_loc = 1, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) error = gfs2_qa_get(dip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) error = gfs2_glock_nq(ghs); /* parent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) goto out_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) error = gfs2_glock_nq(ghs + 1); /* child */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) goto out_child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) error = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) if (inode->i_nlink == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) error = gfs2_permission(dir, MAY_WRITE | MAY_EXEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) error = gfs2_dir_check(dir, &dentry->d_name, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) switch (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) error = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) if (!dip->i_inode.i_nlink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) error = -EFBIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) if (dip->i_entries == (u32)-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) error = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) if (!ip->i_inode.i_nlink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) error = -EMLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) if (ip->i_inode.i_nlink == (u32)-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) error = gfs2_diradd_alloc_required(dir, &dentry->d_name, &da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) if (da.nr_blocks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) struct gfs2_alloc_parms ap = { .target = da.nr_blocks, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) error = gfs2_quota_lock_check(dip, &ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) error = gfs2_inplace_reserve(dip, &ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) goto out_gunlock_q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) error = gfs2_trans_begin(sdp, gfs2_trans_da_blks(dip, &da, 2), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) goto out_ipres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) goto out_ipres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) error = gfs2_meta_inode_buffer(ip, &dibh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) goto out_end_trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) error = gfs2_dir_add(dir, &dentry->d_name, ip, &da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) goto out_brelse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) gfs2_trans_add_meta(ip->i_gl, dibh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) inc_nlink(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) ip->i_inode.i_ctime = current_time(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) ihold(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) out_brelse:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) brelse(dibh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) out_end_trans:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) gfs2_trans_end(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) out_ipres:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) if (da.nr_blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) gfs2_inplace_release(dip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) out_gunlock_q:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) if (da.nr_blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) gfs2_quota_unlock(dip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) out_gunlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) gfs2_dir_no_add(&da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) gfs2_glock_dq(ghs + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) out_child:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) gfs2_glock_dq(ghs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) out_parent:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) gfs2_qa_put(dip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) gfs2_holder_uninit(ghs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) gfs2_holder_uninit(ghs + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) * gfs2_unlink_ok - check to see that a inode is still in a directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) * @dip: the directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) * @name: the name of the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) * @ip: the inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) * Assumes that the lock on (at least) @dip is held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) * Returns: 0 if the parent/child relationship is correct, errno if it isn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) static int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) const struct gfs2_inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) if (IS_IMMUTABLE(&ip->i_inode) || IS_APPEND(&ip->i_inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) if ((dip->i_inode.i_mode & S_ISVTX) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) !uid_eq(dip->i_inode.i_uid, current_fsuid()) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) !uid_eq(ip->i_inode.i_uid, current_fsuid()) && !capable(CAP_FOWNER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) if (IS_APPEND(&dip->i_inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) return gfs2_dir_check(&dip->i_inode, name, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) }
^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) * gfs2_unlink_inode - Removes an inode from its parent dir and unlinks it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) * @dip: The parent directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) * @name: The name of the entry in the parent directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) * @inode: The inode to be removed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) * Called with all the locks and in a transaction. This will only be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) * called for a directory after it has been checked to ensure it is empty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) * Returns: 0 on success, or an error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) static int gfs2_unlink_inode(struct gfs2_inode *dip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) const struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) struct gfs2_inode *ip = GFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) error = gfs2_dir_del(dip, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) ip->i_entries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) clear_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) drop_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) if (inode->i_nlink == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) gfs2_unlink_di(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) * gfs2_unlink - Unlink an inode (this does rmdir as well)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) * @dir: The inode of the directory containing the inode to unlink
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) * @dentry: The file itself
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) * This routine uses the type of the inode as a flag to figure out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) * whether this is an unlink or an rmdir.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) struct gfs2_inode *dip = GFS2_I(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) struct gfs2_sbd *sdp = GFS2_SB(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) struct gfs2_inode *ip = GFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) struct gfs2_holder ghs[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) struct gfs2_rgrpd *rgd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) error = gfs2_rindex_update(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) error = -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) if (!rgd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) goto out_inodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) error = gfs2_glock_nq(ghs); /* parent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) goto out_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) error = gfs2_glock_nq(ghs + 1); /* child */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) goto out_child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) error = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) if (inode->i_nlink == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) goto out_rgrp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) if (S_ISDIR(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) error = -ENOTEMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) if (ip->i_entries > 2 || inode->i_nlink > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) goto out_rgrp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) error = gfs2_glock_nq(ghs + 2); /* rgrp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) goto out_rgrp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) error = gfs2_trans_begin(sdp, 2*RES_DINODE + 3*RES_LEAF + RES_RG_BIT, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) error = gfs2_unlink_inode(dip, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) gfs2_trans_end(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) out_gunlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) gfs2_glock_dq(ghs + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) out_rgrp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) gfs2_glock_dq(ghs + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) out_child:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) gfs2_glock_dq(ghs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) out_parent:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) gfs2_holder_uninit(ghs + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) out_inodes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) gfs2_holder_uninit(ghs + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) gfs2_holder_uninit(ghs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) * gfs2_symlink - Create a symlink
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) * @dir: The directory to create the symlink in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) * @dentry: The dentry to put the symlink in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) * @symname: The thing which the link points to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) const char *symname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) unsigned int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) size = strlen(symname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) if (size >= gfs2_max_stuffed_size(GFS2_I(dir)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) return -ENAMETOOLONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) return gfs2_create_inode(dir, dentry, NULL, S_IFLNK | S_IRWXUGO, 0, symname, size, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) * gfs2_mkdir - Make a directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) * @dir: The parent directory of the new one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) * @dentry: The dentry of the new directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) * @mode: The mode of the new directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) * Returns: errno
^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) static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) unsigned dsize = gfs2_max_stuffed_size(GFS2_I(dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) return gfs2_create_inode(dir, dentry, NULL, S_IFDIR | mode, 0, NULL, dsize, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) }
^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) * gfs2_mknod - Make a special file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) * @dir: The directory in which the special file will reside
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) * @dentry: The dentry of the special file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) * @mode: The mode of the special file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) * @dev: The device specification of the special file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) static int gfs2_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) dev_t dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) return gfs2_create_inode(dir, dentry, NULL, mode, dev, NULL, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) * gfs2_atomic_open - Atomically open a file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) * @dir: The directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) * @dentry: The proposed new entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) * @file: The proposed new struct file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) * @flags: open flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) * @mode: File mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) * Returns: error code or 0 for success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) static int gfs2_atomic_open(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) struct file *file, unsigned flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) struct dentry *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) bool excl = !!(flags & O_EXCL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) if (!d_in_lookup(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) goto skip_lookup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) d = __gfs2_lookup(dir, dentry, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) if (IS_ERR(d))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) return PTR_ERR(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) if (d != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) dentry = d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) if (d_really_is_positive(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) if (!(file->f_mode & FMODE_OPENED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) return finish_no_open(file, d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) dput(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) return excl && (flags & O_CREAT) ? -EEXIST : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) BUG_ON(d != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) skip_lookup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) if (!(flags & O_CREAT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) return gfs2_create_inode(dir, dentry, file, S_IFREG | mode, 0, NULL, 0, excl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) * gfs2_ok_to_move - check if it's ok to move a directory to another directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) * @this: move this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) * @to: to here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) * Follow @to back to the root and make sure we don't encounter @this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) * Assumes we already hold the rename lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) static int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) struct inode *dir = &to->i_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) struct super_block *sb = dir->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) struct inode *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) igrab(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) if (dir == &this->i_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) if (dir == d_inode(sb->s_root)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) break;
^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) tmp = gfs2_lookupi(dir, &gfs2_qdotdot, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) if (!tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) error = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) if (IS_ERR(tmp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) error = PTR_ERR(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) iput(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) dir = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) iput(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) * update_moved_ino - Update an inode that's being moved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) * @ip: The inode being moved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) * @ndip: The parent directory of the new filename
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) * @dir_rename: True of ip is a directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) static int update_moved_ino(struct gfs2_inode *ip, struct gfs2_inode *ndip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) int dir_rename)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) if (dir_rename)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) return gfs2_dir_mvino(ip, &gfs2_qdotdot, ndip, DT_DIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) ip->i_inode.i_ctime = current_time(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) mark_inode_dirty_sync(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) * gfs2_rename - Rename a file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) * @odir: Parent directory of old file name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) * @odentry: The old dentry of the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) * @ndir: Parent directory of new file name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) * @ndentry: The new dentry of the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) static int gfs2_rename(struct inode *odir, struct dentry *odentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) struct inode *ndir, struct dentry *ndentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) struct gfs2_inode *odip = GFS2_I(odir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) struct gfs2_inode *ndip = GFS2_I(ndir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) struct gfs2_inode *ip = GFS2_I(d_inode(odentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) struct gfs2_inode *nip = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) struct gfs2_sbd *sdp = GFS2_SB(odir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) struct gfs2_holder ghs[4], r_gh, rd_gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) struct gfs2_rgrpd *nrgd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) unsigned int num_gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) int dir_rename = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) struct gfs2_diradd da = { .nr_blocks = 0, .save_loc = 0, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) unsigned int x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) gfs2_holder_mark_uninitialized(&r_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) gfs2_holder_mark_uninitialized(&rd_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) if (d_really_is_positive(ndentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) nip = GFS2_I(d_inode(ndentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) if (ip == nip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) error = gfs2_rindex_update(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) error = gfs2_qa_get(ndip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) if (odip != ndip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 0, &r_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) if (S_ISDIR(ip->i_inode.i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) dir_rename = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) /* don't move a directory into its subdir */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) error = gfs2_ok_to_move(ip, ndip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) goto out_gunlock_r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) num_gh = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, GL_ASYNC, ghs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) if (odip != ndip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE,GL_ASYNC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) ghs + num_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) num_gh++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_ASYNC, ghs + num_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) num_gh++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) if (nip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, GL_ASYNC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) ghs + num_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) num_gh++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) for (x = 0; x < num_gh; x++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) error = gfs2_glock_nq(ghs + x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) error = gfs2_glock_async_wait(num_gh, ghs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) if (nip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) /* Grab the resource group glock for unlink flag twiddling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) * This is the case where the target dinode already exists
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) * so we unlink before doing the rename.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) nrgd = gfs2_blk2rgrpd(sdp, nip->i_no_addr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) if (!nrgd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) error = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) error = gfs2_glock_nq_init(nrgd->rd_gl, LM_ST_EXCLUSIVE, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) &rd_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) error = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) if (ip->i_inode.i_nlink == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) /* Check out the old directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) error = gfs2_unlink_ok(odip, &odentry->d_name, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) /* Check out the new directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) if (nip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) if (nip->i_inode.i_nlink == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) error = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) if (S_ISDIR(nip->i_inode.i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) if (nip->i_entries < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) gfs2_consist_inode(nip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) if (nip->i_entries > 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) error = -ENOTEMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) error = gfs2_permission(ndir, MAY_WRITE | MAY_EXEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) error = gfs2_dir_check(ndir, &ndentry->d_name, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) switch (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) error = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) if (odip != ndip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) if (!ndip->i_inode.i_nlink) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) error = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) if (ndip->i_entries == (u32)-1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) error = -EFBIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) if (S_ISDIR(ip->i_inode.i_mode) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) ndip->i_inode.i_nlink == (u32)-1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) error = -EMLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) /* Check out the dir to be renamed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) if (dir_rename) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) error = gfs2_permission(d_inode(odentry), MAY_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) if (nip == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) error = gfs2_diradd_alloc_required(ndir, &ndentry->d_name, &da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) if (da.nr_blocks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) struct gfs2_alloc_parms ap = { .target = da.nr_blocks, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) error = gfs2_quota_lock_check(ndip, &ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) error = gfs2_inplace_reserve(ndip, &ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) goto out_gunlock_q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) error = gfs2_trans_begin(sdp, gfs2_trans_da_blks(ndip, &da, 4) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 4 * RES_LEAF + 4, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) goto out_ipreserv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) error = gfs2_trans_begin(sdp, 4 * RES_DINODE +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 5 * RES_LEAF + 4, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) /* Remove the target file, if it exists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) if (nip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) error = gfs2_unlink_inode(ndip, ndentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) error = update_moved_ino(ip, ndip, dir_rename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) goto out_end_trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) error = gfs2_dir_del(odip, odentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) goto out_end_trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) error = gfs2_dir_add(ndir, &ndentry->d_name, ip, &da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) goto out_end_trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) out_end_trans:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) gfs2_trans_end(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) out_ipreserv:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) if (da.nr_blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) gfs2_inplace_release(ndip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) out_gunlock_q:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) if (da.nr_blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) gfs2_quota_unlock(ndip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) out_gunlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) gfs2_dir_no_add(&da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) if (gfs2_holder_initialized(&rd_gh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) gfs2_glock_dq_uninit(&rd_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) while (x--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) if (gfs2_holder_queued(ghs + x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) gfs2_glock_dq(ghs + x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) gfs2_holder_uninit(ghs + x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) out_gunlock_r:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) if (gfs2_holder_initialized(&r_gh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) gfs2_glock_dq_uninit(&r_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) gfs2_qa_put(ndip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) * gfs2_exchange - exchange two files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) * @odir: Parent directory of old file name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) * @odentry: The old dentry of the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) * @ndir: Parent directory of new file name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) * @ndentry: The new dentry of the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) * @flags: The rename flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) static int gfs2_exchange(struct inode *odir, struct dentry *odentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) struct inode *ndir, struct dentry *ndentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) struct gfs2_inode *odip = GFS2_I(odir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) struct gfs2_inode *ndip = GFS2_I(ndir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) struct gfs2_inode *oip = GFS2_I(odentry->d_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) struct gfs2_inode *nip = GFS2_I(ndentry->d_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) struct gfs2_sbd *sdp = GFS2_SB(odir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) struct gfs2_holder ghs[4], r_gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) unsigned int num_gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) unsigned int x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) umode_t old_mode = oip->i_inode.i_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) umode_t new_mode = nip->i_inode.i_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) gfs2_holder_mark_uninitialized(&r_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) error = gfs2_rindex_update(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) if (odip != ndip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 0, &r_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) if (S_ISDIR(old_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) /* don't move a directory into its subdir */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) error = gfs2_ok_to_move(oip, ndip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) goto out_gunlock_r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) if (S_ISDIR(new_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) /* don't move a directory into its subdir */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) error = gfs2_ok_to_move(nip, odip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) goto out_gunlock_r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) num_gh = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, GL_ASYNC, ghs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) if (odip != ndip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, GL_ASYNC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) ghs + num_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) num_gh++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) gfs2_holder_init(oip->i_gl, LM_ST_EXCLUSIVE, GL_ASYNC, ghs + num_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) num_gh++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, GL_ASYNC, ghs + num_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) num_gh++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) for (x = 0; x < num_gh; x++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) error = gfs2_glock_nq(ghs + x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) error = gfs2_glock_async_wait(num_gh, ghs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) error = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) if (oip->i_inode.i_nlink == 0 || nip->i_inode.i_nlink == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) error = gfs2_unlink_ok(odip, &odentry->d_name, oip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) if (S_ISDIR(old_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) error = gfs2_permission(odentry->d_inode, MAY_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) if (S_ISDIR(new_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) error = gfs2_permission(ndentry->d_inode, MAY_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) error = gfs2_trans_begin(sdp, 4 * RES_DINODE + 4 * RES_LEAF, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) goto out_gunlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) error = update_moved_ino(oip, ndip, S_ISDIR(old_mode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) goto out_end_trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) error = update_moved_ino(nip, odip, S_ISDIR(new_mode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) goto out_end_trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) error = gfs2_dir_mvino(ndip, &ndentry->d_name, oip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) IF2DT(old_mode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) goto out_end_trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) error = gfs2_dir_mvino(odip, &odentry->d_name, nip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) IF2DT(new_mode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) goto out_end_trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) if (odip != ndip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) if (S_ISDIR(new_mode) && !S_ISDIR(old_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) inc_nlink(&odip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) drop_nlink(&ndip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) } else if (S_ISDIR(old_mode) && !S_ISDIR(new_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) inc_nlink(&ndip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) drop_nlink(&odip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) mark_inode_dirty(&ndip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) if (odip != ndip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) mark_inode_dirty(&odip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) out_end_trans:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) gfs2_trans_end(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) out_gunlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) while (x--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) if (gfs2_holder_queued(ghs + x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) gfs2_glock_dq(ghs + x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) gfs2_holder_uninit(ghs + x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) out_gunlock_r:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) if (gfs2_holder_initialized(&r_gh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) gfs2_glock_dq_uninit(&r_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) static int gfs2_rename2(struct inode *odir, struct dentry *odentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) struct inode *ndir, struct dentry *ndentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) flags &= ~RENAME_NOREPLACE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) if (flags & ~RENAME_EXCHANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) if (flags & RENAME_EXCHANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) return gfs2_exchange(odir, odentry, ndir, ndentry, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) return gfs2_rename(odir, odentry, ndir, ndentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) * gfs2_get_link - Follow a symbolic link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) * @dentry: The dentry of the link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) * @inode: The inode of the link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) * @done: destructor for return value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) * This can handle symlinks of any size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) * Returns: 0 on success or error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) static const char *gfs2_get_link(struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) struct delayed_call *done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) struct gfs2_inode *ip = GFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) struct gfs2_holder i_gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) struct buffer_head *dibh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) unsigned int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) if (!dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) return ERR_PTR(-ECHILD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) error = gfs2_glock_nq(&i_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) gfs2_holder_uninit(&i_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) return ERR_PTR(error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) size = (unsigned int)i_size_read(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) if (size == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) gfs2_consist_inode(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) buf = ERR_PTR(-EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) error = gfs2_meta_inode_buffer(ip, &dibh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) buf = ERR_PTR(error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) buf = kzalloc(size + 1, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) buf = ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) memcpy(buf, dibh->b_data + sizeof(struct gfs2_dinode), size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) brelse(dibh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) gfs2_glock_dq_uninit(&i_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) if (!IS_ERR(buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) set_delayed_call(done, kfree_link, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) * gfs2_permission -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) * @inode: The inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) * @mask: The mask to be tested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) * @flags: Indicates whether this is an RCU path walk or not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) * This may be called from the VFS directly, or from within GFS2 with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) * inode locked, so we look to see if the glock is already locked and only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) * lock the glock if its not already been done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) int gfs2_permission(struct inode *inode, int mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) struct gfs2_inode *ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) struct gfs2_holder i_gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) gfs2_holder_mark_uninitialized(&i_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) ip = GFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) if (mask & MAY_NOT_BLOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) return -ECHILD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) if ((mask & MAY_WRITE) && IS_IMMUTABLE(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) error = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) error = generic_permission(inode, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) if (gfs2_holder_initialized(&i_gh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) gfs2_glock_dq_uninit(&i_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) static int __gfs2_setattr_simple(struct inode *inode, struct iattr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) setattr_copy(inode, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) * gfs2_setattr_simple -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) * @ip:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) * @attr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) int gfs2_setattr_simple(struct inode *inode, struct iattr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) if (current->journal_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) return __gfs2_setattr_simple(inode, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) error = gfs2_trans_begin(GFS2_SB(inode), RES_DINODE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) error = __gfs2_setattr_simple(inode, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) gfs2_trans_end(GFS2_SB(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) static int setattr_chown(struct inode *inode, struct iattr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) struct gfs2_inode *ip = GFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) struct gfs2_sbd *sdp = GFS2_SB(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) kuid_t ouid, nuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) kgid_t ogid, ngid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) struct gfs2_alloc_parms ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) ouid = inode->i_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) ogid = inode->i_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) nuid = attr->ia_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) ngid = attr->ia_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) if (!(attr->ia_valid & ATTR_UID) || uid_eq(ouid, nuid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) ouid = nuid = NO_UID_QUOTA_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) if (!(attr->ia_valid & ATTR_GID) || gid_eq(ogid, ngid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) ogid = ngid = NO_GID_QUOTA_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) error = gfs2_qa_get(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) error = gfs2_rindex_update(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) error = gfs2_quota_lock(ip, nuid, ngid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) ap.target = gfs2_get_inode_blocks(&ip->i_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) if (!uid_eq(ouid, NO_UID_QUOTA_CHANGE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) !gid_eq(ogid, NO_GID_QUOTA_CHANGE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) error = gfs2_quota_check(ip, nuid, ngid, &ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) goto out_gunlock_q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) goto out_gunlock_q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) error = gfs2_setattr_simple(inode, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) goto out_end_trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) if (!uid_eq(ouid, NO_UID_QUOTA_CHANGE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) !gid_eq(ogid, NO_GID_QUOTA_CHANGE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) gfs2_quota_change(ip, -(s64)ap.target, ouid, ogid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) gfs2_quota_change(ip, ap.target, nuid, ngid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) out_end_trans:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) gfs2_trans_end(sdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) out_gunlock_q:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) gfs2_quota_unlock(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) gfs2_qa_put(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) * gfs2_setattr - Change attributes on an inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) * @dentry: The dentry which is changing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) * @attr: The structure describing the change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) * The VFS layer wants to change one or more of an inodes attributes. Write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) * that change out to disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) struct gfs2_inode *ip = GFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) struct gfs2_holder i_gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) error = gfs2_qa_get(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) error = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) error = setattr_prepare(dentry, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) if (attr->ia_valid & ATTR_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) error = gfs2_setattr_size(inode, attr->ia_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) else if (attr->ia_valid & (ATTR_UID | ATTR_GID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) error = setattr_chown(inode, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) error = gfs2_setattr_simple(inode, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) if (!error && attr->ia_valid & ATTR_MODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) error = posix_acl_chmod(inode, inode->i_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) gfs2_glock_dq_uninit(&i_gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) gfs2_qa_put(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) * gfs2_getattr - Read out an inode's attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) * @path: Object to query
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) * @stat: The inode's stats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) * @request_mask: Mask of STATX_xxx flags indicating the caller's interests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) * @flags: AT_STATX_xxx setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) * This may be called from the VFS directly, or from within GFS2 with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) * inode locked, so we look to see if the glock is already locked and only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) * lock the glock if its not already been done. Note that its the NFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) * readdirplus operation which causes this to be called (from filldir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) * with the glock already held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) * Returns: errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) static int gfs2_getattr(const struct path *path, struct kstat *stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) u32 request_mask, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) struct inode *inode = d_inode(path->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) struct gfs2_inode *ip = GFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) struct gfs2_holder gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) u32 gfsflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) gfs2_holder_mark_uninitialized(&gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) gfsflags = ip->i_diskflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) if (gfsflags & GFS2_DIF_APPENDONLY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) stat->attributes |= STATX_ATTR_APPEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) if (gfsflags & GFS2_DIF_IMMUTABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) stat->attributes |= STATX_ATTR_IMMUTABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) stat->attributes_mask |= (STATX_ATTR_APPEND |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) STATX_ATTR_COMPRESSED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) STATX_ATTR_ENCRYPTED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) STATX_ATTR_IMMUTABLE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) STATX_ATTR_NODUMP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) generic_fillattr(inode, stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) if (gfs2_holder_initialized(&gh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) gfs2_glock_dq_uninit(&gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) u64 start, u64 len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) struct gfs2_inode *ip = GFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) struct gfs2_holder gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) inode_lock_shared(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) ret = iomap_fiemap(inode, fieinfo, start, len, &gfs2_iomap_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) gfs2_glock_dq_uninit(&gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) inode_unlock_shared(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) loff_t gfs2_seek_data(struct file *file, loff_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) struct inode *inode = file->f_mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) struct gfs2_inode *ip = GFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) struct gfs2_holder gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) loff_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) inode_lock_shared(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) ret = iomap_seek_data(inode, offset, &gfs2_iomap_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) gfs2_glock_dq_uninit(&gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) inode_unlock_shared(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) return vfs_setpos(file, ret, inode->i_sb->s_maxbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) loff_t gfs2_seek_hole(struct file *file, loff_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) struct inode *inode = file->f_mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) struct gfs2_inode *ip = GFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) struct gfs2_holder gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) loff_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) inode_lock_shared(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) ret = iomap_seek_hole(inode, offset, &gfs2_iomap_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) gfs2_glock_dq_uninit(&gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) inode_unlock_shared(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) return vfs_setpos(file, ret, inode->i_sb->s_maxbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) static int gfs2_update_time(struct inode *inode, struct timespec64 *time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) struct gfs2_inode *ip = GFS2_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) struct gfs2_glock *gl = ip->i_gl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) struct gfs2_holder *gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) gh = gfs2_glock_is_locked_by_me(gl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) if (gh && !gfs2_glock_is_held_excl(gl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) gfs2_glock_dq(gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) gfs2_holder_reinit(LM_ST_EXCLUSIVE, 0, gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) error = gfs2_glock_nq(gh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) return generic_update_time(inode, time, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) const struct inode_operations gfs2_file_iops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) .permission = gfs2_permission,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) .setattr = gfs2_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) .getattr = gfs2_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) .listxattr = gfs2_listxattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) .fiemap = gfs2_fiemap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) .get_acl = gfs2_get_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) .set_acl = gfs2_set_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) .update_time = gfs2_update_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) const struct inode_operations gfs2_dir_iops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) .create = gfs2_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) .lookup = gfs2_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) .link = gfs2_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) .unlink = gfs2_unlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) .symlink = gfs2_symlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) .mkdir = gfs2_mkdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) .rmdir = gfs2_unlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) .mknod = gfs2_mknod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) .rename = gfs2_rename2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) .permission = gfs2_permission,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) .setattr = gfs2_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) .getattr = gfs2_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) .listxattr = gfs2_listxattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) .fiemap = gfs2_fiemap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) .get_acl = gfs2_get_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) .set_acl = gfs2_set_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) .update_time = gfs2_update_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) .atomic_open = gfs2_atomic_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) const struct inode_operations gfs2_symlink_iops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) .get_link = gfs2_get_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) .permission = gfs2_permission,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) .setattr = gfs2_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) .getattr = gfs2_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) .listxattr = gfs2_listxattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) .fiemap = gfs2_fiemap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179)