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