David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
Steven Whitehouse | 3a8a9a1 | 2006-05-18 15:09:15 -0400 | [diff] [blame] | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 4 | * |
| 5 | * This copyrighted material is made available to anyone wishing to use, |
| 6 | * modify, copy, or redistribute it subject to the terms and conditions |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 7 | * of the GNU General Public License version 2. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 10 | #include <linux/slab.h> |
| 11 | #include <linux/spinlock.h> |
| 12 | #include <linux/completion.h> |
| 13 | #include <linux/buffer_head.h> |
| 14 | #include <linux/namei.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 15 | #include <linux/mm.h> |
| 16 | #include <linux/xattr.h> |
| 17 | #include <linux/posix_acl.h> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 18 | #include <linux/gfs2_ondisk.h> |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 19 | #include <linux/crc32.h> |
Steven Whitehouse | e9079cc | 2008-10-14 14:43:29 +0100 | [diff] [blame] | 20 | #include <linux/fiemap.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 21 | #include <asm/uaccess.h> |
| 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" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * gfs2_create - Create a file |
| 40 | * @dir: The directory in which to create the file |
| 41 | * @dentry: The dentry of the new file |
| 42 | * @mode: The mode of the new file |
| 43 | * |
| 44 | * Returns: errno |
| 45 | */ |
| 46 | |
| 47 | static int gfs2_create(struct inode *dir, struct dentry *dentry, |
| 48 | int mode, struct nameidata *nd) |
| 49 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 50 | struct gfs2_inode *dip = GFS2_I(dir); |
| 51 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 52 | struct gfs2_holder ghs[2]; |
| 53 | struct inode *inode; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 54 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 55 | gfs2_holder_init(dip->i_gl, 0, 0, ghs); |
| 56 | |
| 57 | for (;;) { |
Steven Whitehouse | e7f14f4 | 2006-10-31 21:45:08 -0500 | [diff] [blame] | 58 | inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode, 0); |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 59 | if (!IS_ERR(inode)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 60 | gfs2_trans_end(sdp); |
Steven Whitehouse | 6dbd822 | 2008-01-10 15:18:55 +0000 | [diff] [blame] | 61 | if (dip->i_alloc->al_rgd) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 62 | gfs2_inplace_release(dip); |
| 63 | gfs2_quota_unlock(dip); |
| 64 | gfs2_alloc_put(dip); |
| 65 | gfs2_glock_dq_uninit_m(2, ghs); |
Steven Whitehouse | 3a8476d | 2006-06-19 09:10:39 -0400 | [diff] [blame] | 66 | mark_inode_dirty(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 67 | break; |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 68 | } else if (PTR_ERR(inode) != -EEXIST || |
Al Viro | 3516586 | 2008-08-05 03:00:49 -0400 | [diff] [blame] | 69 | (nd && nd->flags & LOOKUP_EXCL)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 70 | gfs2_holder_uninit(ghs); |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 71 | return PTR_ERR(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Al Viro | a569c71 | 2008-07-23 14:42:05 -0400 | [diff] [blame] | 74 | inode = gfs2_lookupi(dir, &dentry->d_name, 0); |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 75 | if (inode) { |
| 76 | if (!IS_ERR(inode)) { |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 77 | gfs2_holder_uninit(ghs); |
| 78 | break; |
| 79 | } else { |
| 80 | gfs2_holder_uninit(ghs); |
| 81 | return PTR_ERR(inode); |
| 82 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 86 | d_instantiate(dentry, inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * gfs2_lookup - Look up a filename in a directory and return its inode |
| 93 | * @dir: The directory inode |
| 94 | * @dentry: The dentry of the new inode |
| 95 | * @nd: passed from Linux VFS, ignored by us |
| 96 | * |
| 97 | * Called by the VFS layer. Lock dir and call gfs2_lookupi() |
| 98 | * |
| 99 | * Returns: errno |
| 100 | */ |
| 101 | |
| 102 | static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry, |
| 103 | struct nameidata *nd) |
| 104 | { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 105 | struct inode *inode = NULL; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 106 | |
Al Viro | a569c71 | 2008-07-23 14:42:05 -0400 | [diff] [blame] | 107 | inode = gfs2_lookupi(dir, &dentry->d_name, 0); |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 108 | if (inode && IS_ERR(inode)) |
David Howells | e231c2e | 2008-02-07 00:15:26 -0800 | [diff] [blame] | 109 | return ERR_CAST(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 110 | |
Steven Whitehouse | 9656b2c | 2008-01-08 08:14:30 +0000 | [diff] [blame] | 111 | if (inode) { |
| 112 | struct gfs2_glock *gl = GFS2_I(inode)->i_gl; |
| 113 | struct gfs2_holder gh; |
| 114 | int error; |
| 115 | error = gfs2_glock_nq_init(gl, LM_ST_SHARED, LM_FLAG_ANY, &gh); |
| 116 | if (error) { |
| 117 | iput(inode); |
| 118 | return ERR_PTR(error); |
| 119 | } |
| 120 | gfs2_glock_dq_uninit(&gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 121 | return d_splice_alias(inode, dentry); |
Steven Whitehouse | 9656b2c | 2008-01-08 08:14:30 +0000 | [diff] [blame] | 122 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 123 | d_add(dentry, inode); |
| 124 | |
| 125 | return NULL; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * gfs2_link - Link to a file |
| 130 | * @old_dentry: The inode to link |
| 131 | * @dir: Add link to this directory |
| 132 | * @dentry: The name of the link |
| 133 | * |
| 134 | * Link the inode in "old_dentry" into the directory "dir" with the |
| 135 | * name in "dentry". |
| 136 | * |
| 137 | * Returns: errno |
| 138 | */ |
| 139 | |
| 140 | static int gfs2_link(struct dentry *old_dentry, struct inode *dir, |
| 141 | struct dentry *dentry) |
| 142 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 143 | struct gfs2_inode *dip = GFS2_I(dir); |
| 144 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 145 | struct inode *inode = old_dentry->d_inode; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 146 | struct gfs2_inode *ip = GFS2_I(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 147 | struct gfs2_holder ghs[2]; |
Steven Whitehouse | 2baee03 | 2011-05-09 12:08:36 +0100 | [diff] [blame] | 148 | struct buffer_head *dibh; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 149 | int alloc_required; |
| 150 | int error; |
| 151 | |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 152 | if (S_ISDIR(inode->i_mode)) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 153 | return -EPERM; |
| 154 | |
| 155 | gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); |
| 156 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); |
| 157 | |
Bob Peterson | 72dbf47 | 2008-08-12 13:39:29 -0500 | [diff] [blame] | 158 | error = gfs2_glock_nq(ghs); /* parent */ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 159 | if (error) |
Bob Peterson | 72dbf47 | 2008-08-12 13:39:29 -0500 | [diff] [blame] | 160 | goto out_parent; |
| 161 | |
| 162 | error = gfs2_glock_nq(ghs + 1); /* child */ |
| 163 | if (error) |
| 164 | goto out_child; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 165 | |
Steven Whitehouse | d192a8e | 2011-05-05 12:35:40 +0100 | [diff] [blame] | 166 | error = -ENOENT; |
| 167 | if (inode->i_nlink == 0) |
| 168 | goto out_gunlock; |
| 169 | |
Nick Piggin | b74c79e | 2011-01-07 17:49:58 +1100 | [diff] [blame] | 170 | error = gfs2_permission(dir, MAY_WRITE | MAY_EXEC, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 171 | if (error) |
| 172 | goto out_gunlock; |
| 173 | |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 174 | error = gfs2_dir_check(dir, &dentry->d_name, NULL); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 175 | switch (error) { |
| 176 | case -ENOENT: |
| 177 | break; |
| 178 | case 0: |
| 179 | error = -EEXIST; |
| 180 | default: |
| 181 | goto out_gunlock; |
| 182 | } |
| 183 | |
| 184 | error = -EINVAL; |
Steven Whitehouse | 4f56110 | 2006-11-01 14:04:17 -0500 | [diff] [blame] | 185 | if (!dip->i_inode.i_nlink) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 186 | goto out_gunlock; |
| 187 | error = -EFBIG; |
Steven Whitehouse | ad6203f2 | 2008-11-03 13:59:19 +0000 | [diff] [blame] | 188 | if (dip->i_entries == (u32)-1) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 189 | goto out_gunlock; |
| 190 | error = -EPERM; |
| 191 | if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
| 192 | goto out_gunlock; |
| 193 | error = -EINVAL; |
Steven Whitehouse | 4f56110 | 2006-11-01 14:04:17 -0500 | [diff] [blame] | 194 | if (!ip->i_inode.i_nlink) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 195 | goto out_gunlock; |
| 196 | error = -EMLINK; |
Steven Whitehouse | 4f56110 | 2006-11-01 14:04:17 -0500 | [diff] [blame] | 197 | if (ip->i_inode.i_nlink == (u32)-1) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 198 | goto out_gunlock; |
| 199 | |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 200 | alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name); |
| 201 | if (error < 0) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 202 | goto out_gunlock; |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 203 | error = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 204 | |
| 205 | if (alloc_required) { |
| 206 | struct gfs2_alloc *al = gfs2_alloc_get(dip); |
Cyrill Gorcunov | 182fe5a | 2008-03-03 21:54:21 +0300 | [diff] [blame] | 207 | if (!al) { |
| 208 | error = -ENOMEM; |
| 209 | goto out_gunlock; |
| 210 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 211 | |
Steven Whitehouse | d82661d | 2008-03-10 15:34:50 +0000 | [diff] [blame] | 212 | error = gfs2_quota_lock_check(dip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 213 | if (error) |
| 214 | goto out_alloc; |
| 215 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 216 | al->al_requested = sdp->sd_max_dirres; |
| 217 | |
| 218 | error = gfs2_inplace_reserve(dip); |
| 219 | if (error) |
| 220 | goto out_gunlock_q; |
| 221 | |
Steven Whitehouse | 1b50259 | 2006-05-18 14:10:52 -0400 | [diff] [blame] | 222 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + |
Benjamin Marzinski | bf97b67 | 2010-09-27 16:00:04 -0500 | [diff] [blame] | 223 | gfs2_rg_blocks(al) + |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 224 | 2 * RES_DINODE + RES_STATFS + |
| 225 | RES_QUOTA, 0); |
| 226 | if (error) |
| 227 | goto out_ipres; |
| 228 | } else { |
| 229 | error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0); |
| 230 | if (error) |
| 231 | goto out_ipres; |
| 232 | } |
| 233 | |
Steven Whitehouse | 2baee03 | 2011-05-09 12:08:36 +0100 | [diff] [blame] | 234 | error = gfs2_meta_inode_buffer(ip, &dibh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 235 | if (error) |
| 236 | goto out_end_trans; |
| 237 | |
Steven Whitehouse | 3d6ecb7 | 2011-05-09 13:30:08 +0100 | [diff] [blame] | 238 | error = gfs2_dir_add(dir, &dentry->d_name, ip); |
Steven Whitehouse | 2baee03 | 2011-05-09 12:08:36 +0100 | [diff] [blame] | 239 | if (error) |
| 240 | goto out_brelse; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 241 | |
Steven Whitehouse | 2baee03 | 2011-05-09 12:08:36 +0100 | [diff] [blame] | 242 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
| 243 | inc_nlink(&ip->i_inode); |
| 244 | ip->i_inode.i_ctime = CURRENT_TIME; |
| 245 | gfs2_dinode_out(ip, dibh->b_data); |
| 246 | mark_inode_dirty(&ip->i_inode); |
| 247 | |
| 248 | out_brelse: |
| 249 | brelse(dibh); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 250 | out_end_trans: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 251 | gfs2_trans_end(sdp); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 252 | out_ipres: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 253 | if (alloc_required) |
| 254 | gfs2_inplace_release(dip); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 255 | out_gunlock_q: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 256 | if (alloc_required) |
| 257 | gfs2_quota_unlock(dip); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 258 | out_alloc: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 259 | if (alloc_required) |
| 260 | gfs2_alloc_put(dip); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 261 | out_gunlock: |
Bob Peterson | 72dbf47 | 2008-08-12 13:39:29 -0500 | [diff] [blame] | 262 | gfs2_glock_dq(ghs + 1); |
| 263 | out_child: |
| 264 | gfs2_glock_dq(ghs); |
| 265 | out_parent: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 266 | gfs2_holder_uninit(ghs); |
| 267 | gfs2_holder_uninit(ghs + 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 268 | if (!error) { |
Al Viro | 7de9c6ee | 2010-10-23 11:11:40 -0400 | [diff] [blame] | 269 | ihold(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 270 | d_instantiate(dentry, inode); |
| 271 | mark_inode_dirty(inode); |
| 272 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 273 | return error; |
| 274 | } |
| 275 | |
Steven Whitehouse | 87ec217 | 2009-05-22 10:54:50 +0100 | [diff] [blame] | 276 | /* |
| 277 | * gfs2_unlink_ok - check to see that a inode is still in a directory |
| 278 | * @dip: the directory |
| 279 | * @name: the name of the file |
| 280 | * @ip: the inode |
| 281 | * |
| 282 | * Assumes that the lock on (at least) @dip is held. |
| 283 | * |
| 284 | * Returns: 0 if the parent/child relationship is correct, errno if it isn't |
| 285 | */ |
| 286 | |
| 287 | static int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name, |
| 288 | const struct gfs2_inode *ip) |
| 289 | { |
| 290 | int error; |
| 291 | |
| 292 | if (IS_IMMUTABLE(&ip->i_inode) || IS_APPEND(&ip->i_inode)) |
| 293 | return -EPERM; |
| 294 | |
| 295 | if ((dip->i_inode.i_mode & S_ISVTX) && |
| 296 | dip->i_inode.i_uid != current_fsuid() && |
| 297 | ip->i_inode.i_uid != current_fsuid() && !capable(CAP_FOWNER)) |
| 298 | return -EPERM; |
| 299 | |
| 300 | if (IS_APPEND(&dip->i_inode)) |
| 301 | return -EPERM; |
| 302 | |
Nick Piggin | b74c79e | 2011-01-07 17:49:58 +1100 | [diff] [blame] | 303 | error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC, 0); |
Steven Whitehouse | 87ec217 | 2009-05-22 10:54:50 +0100 | [diff] [blame] | 304 | if (error) |
| 305 | return error; |
| 306 | |
| 307 | error = gfs2_dir_check(&dip->i_inode, name, ip); |
| 308 | if (error) |
| 309 | return error; |
| 310 | |
| 311 | return 0; |
| 312 | } |
| 313 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 314 | /** |
Steven Whitehouse | 855d23c | 2011-05-09 16:42:37 +0100 | [diff] [blame] | 315 | * gfs2_unlink_inode - Removes an inode from its parent dir and unlinks it |
| 316 | * @dip: The parent directory |
| 317 | * @name: The name of the entry in the parent directory |
| 318 | * @bh: The inode buffer for the inode to be removed |
| 319 | * @inode: The inode to be removed |
| 320 | * |
| 321 | * Called with all the locks and in a transaction. This will only be |
| 322 | * called for a directory after it has been checked to ensure it is empty. |
| 323 | * |
| 324 | * Returns: 0 on success, or an error |
| 325 | */ |
| 326 | |
| 327 | static int gfs2_unlink_inode(struct gfs2_inode *dip, |
| 328 | const struct dentry *dentry, |
| 329 | struct buffer_head *bh) |
| 330 | { |
| 331 | struct inode *inode = dentry->d_inode; |
| 332 | struct gfs2_inode *ip = GFS2_I(inode); |
| 333 | int error; |
| 334 | |
| 335 | error = gfs2_dir_del(dip, dentry); |
| 336 | if (error) |
| 337 | return error; |
| 338 | |
| 339 | ip->i_entries = 0; |
| 340 | inode->i_ctime = CURRENT_TIME; |
| 341 | if (S_ISDIR(inode->i_mode)) |
| 342 | clear_nlink(inode); |
| 343 | else |
| 344 | drop_nlink(inode); |
| 345 | gfs2_trans_add_bh(ip->i_gl, bh, 1); |
| 346 | gfs2_dinode_out(ip, bh->b_data); |
| 347 | mark_inode_dirty(inode); |
| 348 | if (inode->i_nlink == 0) |
| 349 | gfs2_unlink_di(inode); |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | |
| 354 | /** |
| 355 | * gfs2_unlink - Unlink an inode (this does rmdir as well) |
| 356 | * @dir: The inode of the directory containing the inode to unlink |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 357 | * @dentry: The file itself |
| 358 | * |
Steven Whitehouse | 855d23c | 2011-05-09 16:42:37 +0100 | [diff] [blame] | 359 | * This routine uses the type of the inode as a flag to figure out |
| 360 | * whether this is an unlink or an rmdir. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 361 | * |
| 362 | * Returns: errno |
| 363 | */ |
| 364 | |
| 365 | static int gfs2_unlink(struct inode *dir, struct dentry *dentry) |
| 366 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 367 | struct gfs2_inode *dip = GFS2_I(dir); |
| 368 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
Steven Whitehouse | 855d23c | 2011-05-09 16:42:37 +0100 | [diff] [blame] | 369 | struct inode *inode = dentry->d_inode; |
| 370 | struct gfs2_inode *ip = GFS2_I(inode); |
| 371 | struct buffer_head *bh; |
Russell Cattelan | ddee760 | 2007-01-29 17:13:44 -0600 | [diff] [blame] | 372 | struct gfs2_holder ghs[3]; |
| 373 | struct gfs2_rgrpd *rgd; |
| 374 | struct gfs2_holder ri_gh; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 375 | int error; |
| 376 | |
Russell Cattelan | ddee760 | 2007-01-29 17:13:44 -0600 | [diff] [blame] | 377 | error = gfs2_rindex_hold(sdp, &ri_gh); |
| 378 | if (error) |
| 379 | return error; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 380 | |
Russell Cattelan | ddee760 | 2007-01-29 17:13:44 -0600 | [diff] [blame] | 381 | gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); |
| 382 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); |
| 383 | |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 384 | rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr); |
Russell Cattelan | ddee760 | 2007-01-29 17:13:44 -0600 | [diff] [blame] | 385 | gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2); |
| 386 | |
| 387 | |
Steven Whitehouse | 8497a46 | 2007-08-26 14:23:56 +0100 | [diff] [blame] | 388 | error = gfs2_glock_nq(ghs); /* parent */ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 389 | if (error) |
Steven Whitehouse | 8497a46 | 2007-08-26 14:23:56 +0100 | [diff] [blame] | 390 | goto out_parent; |
| 391 | |
| 392 | error = gfs2_glock_nq(ghs + 1); /* child */ |
| 393 | if (error) |
| 394 | goto out_child; |
| 395 | |
Steven Whitehouse | d192a8e | 2011-05-05 12:35:40 +0100 | [diff] [blame] | 396 | error = -ENOENT; |
Steven Whitehouse | 855d23c | 2011-05-09 16:42:37 +0100 | [diff] [blame] | 397 | if (inode->i_nlink == 0) |
Steven Whitehouse | d192a8e | 2011-05-05 12:35:40 +0100 | [diff] [blame] | 398 | goto out_rgrp; |
| 399 | |
Steven Whitehouse | 855d23c | 2011-05-09 16:42:37 +0100 | [diff] [blame] | 400 | if (S_ISDIR(inode->i_mode)) { |
| 401 | error = -ENOTEMPTY; |
| 402 | if (ip->i_entries > 2 || inode->i_nlink > 2) |
| 403 | goto out_rgrp; |
| 404 | } |
| 405 | |
Steven Whitehouse | 8497a46 | 2007-08-26 14:23:56 +0100 | [diff] [blame] | 406 | error = gfs2_glock_nq(ghs + 2); /* rgrp */ |
| 407 | if (error) |
| 408 | goto out_rgrp; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 409 | |
| 410 | error = gfs2_unlink_ok(dip, &dentry->d_name, ip); |
| 411 | if (error) |
Bob Peterson | 72dbf47 | 2008-08-12 13:39:29 -0500 | [diff] [blame] | 412 | goto out_gunlock; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 413 | |
Steven Whitehouse | 855d23c | 2011-05-09 16:42:37 +0100 | [diff] [blame] | 414 | 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] | 415 | if (error) |
Roel Kluin | cd01207 | 2009-08-22 19:26:42 +0200 | [diff] [blame] | 416 | goto out_gunlock; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 417 | |
Steven Whitehouse | 855d23c | 2011-05-09 16:42:37 +0100 | [diff] [blame] | 418 | error = gfs2_meta_inode_buffer(ip, &bh); |
| 419 | if (error) |
| 420 | goto out_end_trans; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 421 | |
Steven Whitehouse | 855d23c | 2011-05-09 16:42:37 +0100 | [diff] [blame] | 422 | error = gfs2_unlink_inode(dip, dentry, bh); |
| 423 | brelse(bh); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 424 | |
| 425 | out_end_trans: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 426 | gfs2_trans_end(sdp); |
Bob Peterson | 72dbf47 | 2008-08-12 13:39:29 -0500 | [diff] [blame] | 427 | out_gunlock: |
Steven Whitehouse | 8497a46 | 2007-08-26 14:23:56 +0100 | [diff] [blame] | 428 | gfs2_glock_dq(ghs + 2); |
| 429 | out_rgrp: |
Russell Cattelan | ddee760 | 2007-01-29 17:13:44 -0600 | [diff] [blame] | 430 | gfs2_holder_uninit(ghs + 2); |
Steven Whitehouse | 8497a46 | 2007-08-26 14:23:56 +0100 | [diff] [blame] | 431 | gfs2_glock_dq(ghs + 1); |
| 432 | out_child: |
| 433 | gfs2_holder_uninit(ghs + 1); |
| 434 | gfs2_glock_dq(ghs); |
| 435 | out_parent: |
| 436 | gfs2_holder_uninit(ghs); |
Russell Cattelan | ddee760 | 2007-01-29 17:13:44 -0600 | [diff] [blame] | 437 | gfs2_glock_dq_uninit(&ri_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 438 | return error; |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | * gfs2_symlink - Create a symlink |
| 443 | * @dir: The directory to create the symlink in |
| 444 | * @dentry: The dentry to put the symlink in |
| 445 | * @symname: The thing which the link points to |
| 446 | * |
| 447 | * Returns: errno |
| 448 | */ |
| 449 | |
| 450 | static int gfs2_symlink(struct inode *dir, struct dentry *dentry, |
| 451 | const char *symname) |
| 452 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 453 | struct gfs2_inode *dip = GFS2_I(dir), *ip; |
| 454 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 455 | struct gfs2_holder ghs[2]; |
| 456 | struct inode *inode; |
| 457 | struct buffer_head *dibh; |
| 458 | int size; |
| 459 | int error; |
| 460 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 461 | /* Must be stuffed with a null terminator for gfs2_follow_link() */ |
| 462 | size = strlen(symname); |
| 463 | if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1) |
| 464 | return -ENAMETOOLONG; |
| 465 | |
| 466 | gfs2_holder_init(dip->i_gl, 0, 0, ghs); |
| 467 | |
Steven Whitehouse | e7f14f4 | 2006-10-31 21:45:08 -0500 | [diff] [blame] | 468 | inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO, 0); |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 469 | if (IS_ERR(inode)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 470 | gfs2_holder_uninit(ghs); |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 471 | return PTR_ERR(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 474 | ip = ghs[1].gh_gl->gl_object; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 475 | |
Steven Whitehouse | 5cf3252 | 2009-03-31 16:06:27 +0100 | [diff] [blame] | 476 | i_size_write(inode, size); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 477 | |
| 478 | error = gfs2_meta_inode_buffer(ip, &dibh); |
| 479 | |
| 480 | if (!gfs2_assert_withdraw(sdp, !error)) { |
Steven Whitehouse | 539e5d6 | 2006-10-31 15:07:05 -0500 | [diff] [blame] | 481 | gfs2_dinode_out(ip, dibh->b_data); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 482 | memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname, |
| 483 | size); |
| 484 | brelse(dibh); |
| 485 | } |
| 486 | |
| 487 | gfs2_trans_end(sdp); |
Steven Whitehouse | 6dbd822 | 2008-01-10 15:18:55 +0000 | [diff] [blame] | 488 | if (dip->i_alloc->al_rgd) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 489 | gfs2_inplace_release(dip); |
| 490 | gfs2_quota_unlock(dip); |
| 491 | gfs2_alloc_put(dip); |
| 492 | |
| 493 | gfs2_glock_dq_uninit_m(2, ghs); |
| 494 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 495 | d_instantiate(dentry, inode); |
| 496 | mark_inode_dirty(inode); |
| 497 | |
| 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | /** |
| 502 | * gfs2_mkdir - Make a directory |
| 503 | * @dir: The parent directory of the new one |
| 504 | * @dentry: The dentry of the new directory |
| 505 | * @mode: The mode of the new directory |
| 506 | * |
| 507 | * Returns: errno |
| 508 | */ |
| 509 | |
| 510 | static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode) |
| 511 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 512 | struct gfs2_inode *dip = GFS2_I(dir), *ip; |
| 513 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 514 | struct gfs2_holder ghs[2]; |
| 515 | struct inode *inode; |
| 516 | struct buffer_head *dibh; |
| 517 | int error; |
| 518 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 519 | gfs2_holder_init(dip->i_gl, 0, 0, ghs); |
| 520 | |
Steven Whitehouse | e7f14f4 | 2006-10-31 21:45:08 -0500 | [diff] [blame] | 521 | inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode, 0); |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 522 | if (IS_ERR(inode)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 523 | gfs2_holder_uninit(ghs); |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 524 | return PTR_ERR(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 525 | } |
| 526 | |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 527 | ip = ghs[1].gh_gl->gl_object; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 528 | |
Steven Whitehouse | 4f56110 | 2006-11-01 14:04:17 -0500 | [diff] [blame] | 529 | ip->i_inode.i_nlink = 2; |
Steven Whitehouse | a2e0f79 | 2010-08-11 09:53:11 +0100 | [diff] [blame] | 530 | i_size_write(inode, sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)); |
Steven Whitehouse | 383f01f | 2008-11-04 10:05:22 +0000 | [diff] [blame] | 531 | ip->i_diskflags |= GFS2_DIF_JDATA; |
Steven Whitehouse | ad6203f2 | 2008-11-03 13:59:19 +0000 | [diff] [blame] | 532 | ip->i_entries = 2; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 533 | |
| 534 | error = gfs2_meta_inode_buffer(ip, &dibh); |
| 535 | |
| 536 | if (!gfs2_assert_withdraw(sdp, !error)) { |
| 537 | struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data; |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 538 | struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 539 | |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 540 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
Steven Whitehouse | 8d12358 | 2010-09-17 12:30:23 +0100 | [diff] [blame] | 541 | gfs2_qstr2dirent(&gfs2_qdot, GFS2_DIRENT_SIZE(gfs2_qdot.len), dent); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 542 | dent->de_inum = di->di_num; /* already GFS2 endian */ |
Steven Whitehouse | 7ecdb70 | 2006-10-03 21:03:35 -0400 | [diff] [blame] | 543 | dent->de_type = cpu_to_be16(DT_DIR); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 544 | di->di_entries = cpu_to_be32(1); |
| 545 | |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 546 | dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1)); |
Steven Whitehouse | 8d12358 | 2010-09-17 12:30:23 +0100 | [diff] [blame] | 547 | gfs2_qstr2dirent(&gfs2_qdotdot, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 548 | |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 549 | gfs2_inum_out(dip, dent); |
Steven Whitehouse | 7ecdb70 | 2006-10-03 21:03:35 -0400 | [diff] [blame] | 550 | dent->de_type = cpu_to_be16(DT_DIR); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 551 | |
Steven Whitehouse | 539e5d6 | 2006-10-31 15:07:05 -0500 | [diff] [blame] | 552 | gfs2_dinode_out(ip, di); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 553 | |
| 554 | brelse(dibh); |
| 555 | } |
| 556 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 557 | gfs2_trans_end(sdp); |
Steven Whitehouse | 6dbd822 | 2008-01-10 15:18:55 +0000 | [diff] [blame] | 558 | if (dip->i_alloc->al_rgd) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 559 | gfs2_inplace_release(dip); |
| 560 | gfs2_quota_unlock(dip); |
| 561 | gfs2_alloc_put(dip); |
| 562 | |
| 563 | gfs2_glock_dq_uninit_m(2, ghs); |
| 564 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 565 | d_instantiate(dentry, inode); |
| 566 | mark_inode_dirty(inode); |
| 567 | |
| 568 | return 0; |
| 569 | } |
| 570 | |
| 571 | /** |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 572 | * gfs2_mknod - Make a special file |
| 573 | * @dir: The directory in which the special file will reside |
| 574 | * @dentry: The dentry of the special file |
| 575 | * @mode: The mode of the special file |
| 576 | * @rdev: The device specification of the special file |
| 577 | * |
| 578 | */ |
| 579 | |
| 580 | static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode, |
| 581 | dev_t dev) |
| 582 | { |
Steven Whitehouse | e7f14f4 | 2006-10-31 21:45:08 -0500 | [diff] [blame] | 583 | struct gfs2_inode *dip = GFS2_I(dir); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 584 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 585 | struct gfs2_holder ghs[2]; |
| 586 | struct inode *inode; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 587 | |
| 588 | gfs2_holder_init(dip->i_gl, 0, 0, ghs); |
| 589 | |
Steven Whitehouse | e7f14f4 | 2006-10-31 21:45:08 -0500 | [diff] [blame] | 590 | inode = gfs2_createi(ghs, &dentry->d_name, mode, dev); |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 591 | if (IS_ERR(inode)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 592 | gfs2_holder_uninit(ghs); |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 593 | return PTR_ERR(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 594 | } |
| 595 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 596 | gfs2_trans_end(sdp); |
Steven Whitehouse | 6dbd822 | 2008-01-10 15:18:55 +0000 | [diff] [blame] | 597 | if (dip->i_alloc->al_rgd) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 598 | gfs2_inplace_release(dip); |
| 599 | gfs2_quota_unlock(dip); |
| 600 | gfs2_alloc_put(dip); |
| 601 | |
| 602 | gfs2_glock_dq_uninit_m(2, ghs); |
| 603 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 604 | d_instantiate(dentry, inode); |
| 605 | mark_inode_dirty(inode); |
| 606 | |
| 607 | return 0; |
| 608 | } |
| 609 | |
Steven Whitehouse | 0188d6c | 2008-08-26 09:38:26 +0100 | [diff] [blame] | 610 | /* |
| 611 | * gfs2_ok_to_move - check if it's ok to move a directory to another directory |
| 612 | * @this: move this |
| 613 | * @to: to here |
| 614 | * |
| 615 | * Follow @to back to the root and make sure we don't encounter @this |
| 616 | * Assumes we already hold the rename lock. |
| 617 | * |
| 618 | * Returns: errno |
| 619 | */ |
| 620 | |
| 621 | static int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to) |
| 622 | { |
| 623 | struct inode *dir = &to->i_inode; |
| 624 | struct super_block *sb = dir->i_sb; |
| 625 | struct inode *tmp; |
Steven Whitehouse | 0188d6c | 2008-08-26 09:38:26 +0100 | [diff] [blame] | 626 | int error = 0; |
| 627 | |
Steven Whitehouse | 0188d6c | 2008-08-26 09:38:26 +0100 | [diff] [blame] | 628 | igrab(dir); |
| 629 | |
| 630 | for (;;) { |
| 631 | if (dir == &this->i_inode) { |
| 632 | error = -EINVAL; |
| 633 | break; |
| 634 | } |
| 635 | if (dir == sb->s_root->d_inode) { |
| 636 | error = 0; |
| 637 | break; |
| 638 | } |
| 639 | |
Steven Whitehouse | 8d12358 | 2010-09-17 12:30:23 +0100 | [diff] [blame] | 640 | tmp = gfs2_lookupi(dir, &gfs2_qdotdot, 1); |
Steven Whitehouse | 0188d6c | 2008-08-26 09:38:26 +0100 | [diff] [blame] | 641 | if (IS_ERR(tmp)) { |
| 642 | error = PTR_ERR(tmp); |
| 643 | break; |
| 644 | } |
| 645 | |
| 646 | iput(dir); |
| 647 | dir = tmp; |
| 648 | } |
| 649 | |
| 650 | iput(dir); |
| 651 | |
| 652 | return error; |
| 653 | } |
| 654 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 655 | /** |
| 656 | * gfs2_rename - Rename a file |
| 657 | * @odir: Parent directory of old file name |
| 658 | * @odentry: The old dentry of the file |
| 659 | * @ndir: Parent directory of new file name |
| 660 | * @ndentry: The new dentry of the file |
| 661 | * |
| 662 | * Returns: errno |
| 663 | */ |
| 664 | |
| 665 | static int gfs2_rename(struct inode *odir, struct dentry *odentry, |
| 666 | struct inode *ndir, struct dentry *ndentry) |
| 667 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 668 | struct gfs2_inode *odip = GFS2_I(odir); |
| 669 | struct gfs2_inode *ndip = GFS2_I(ndir); |
| 670 | struct gfs2_inode *ip = GFS2_I(odentry->d_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 671 | struct gfs2_inode *nip = NULL; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 672 | struct gfs2_sbd *sdp = GFS2_SB(odir); |
Bob Peterson | 46290341 | 2010-09-30 10:34:00 -0400 | [diff] [blame] | 673 | struct gfs2_holder ghs[5], r_gh = { .gh_gl = NULL, }, ri_gh; |
Russell Cattelan | ddee760 | 2007-01-29 17:13:44 -0600 | [diff] [blame] | 674 | struct gfs2_rgrpd *nrgd; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 675 | unsigned int num_gh; |
| 676 | int dir_rename = 0; |
Steven Whitehouse | 24b977b | 2009-12-09 13:55:12 +0000 | [diff] [blame] | 677 | int alloc_required = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 678 | unsigned int x; |
| 679 | int error; |
| 680 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 681 | if (ndentry->d_inode) { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 682 | nip = GFS2_I(ndentry->d_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 683 | if (ip == nip) |
| 684 | return 0; |
| 685 | } |
| 686 | |
Bob Peterson | 46290341 | 2010-09-30 10:34:00 -0400 | [diff] [blame] | 687 | error = gfs2_rindex_hold(sdp, &ri_gh); |
| 688 | if (error) |
| 689 | return error; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 690 | |
Steven Whitehouse | 0188d6c | 2008-08-26 09:38:26 +0100 | [diff] [blame] | 691 | if (odip != ndip) { |
| 692 | error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE, |
| 693 | 0, &r_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 694 | if (error) |
| 695 | goto out; |
| 696 | |
Steven Whitehouse | 0188d6c | 2008-08-26 09:38:26 +0100 | [diff] [blame] | 697 | if (S_ISDIR(ip->i_inode.i_mode)) { |
| 698 | dir_rename = 1; |
| 699 | /* don't move a dirctory into it's subdir */ |
| 700 | error = gfs2_ok_to_move(ip, ndip); |
| 701 | if (error) |
| 702 | goto out_gunlock_r; |
| 703 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 704 | } |
| 705 | |
Steven Whitehouse | d9d1ca3 | 2006-06-21 15:38:17 -0400 | [diff] [blame] | 706 | num_gh = 1; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 707 | gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); |
Steven Whitehouse | d9d1ca3 | 2006-06-21 15:38:17 -0400 | [diff] [blame] | 708 | if (odip != ndip) { |
| 709 | gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); |
| 710 | num_gh++; |
| 711 | } |
| 712 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); |
| 713 | num_gh++; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 714 | |
Steven Whitehouse | d9d1ca3 | 2006-06-21 15:38:17 -0400 | [diff] [blame] | 715 | if (nip) { |
| 716 | gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); |
| 717 | num_gh++; |
Russell Cattelan | ddee760 | 2007-01-29 17:13:44 -0600 | [diff] [blame] | 718 | /* grab the resource lock for unlink flag twiddling |
| 719 | * this is the case of the target file already existing |
| 720 | * so we unlink before doing the rename |
| 721 | */ |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 722 | nrgd = gfs2_blk2rgrpd(sdp, nip->i_no_addr); |
Russell Cattelan | ddee760 | 2007-01-29 17:13:44 -0600 | [diff] [blame] | 723 | if (nrgd) |
| 724 | gfs2_holder_init(nrgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++); |
Steven Whitehouse | d9d1ca3 | 2006-06-21 15:38:17 -0400 | [diff] [blame] | 725 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 726 | |
Bob Peterson | 72dbf47 | 2008-08-12 13:39:29 -0500 | [diff] [blame] | 727 | for (x = 0; x < num_gh; x++) { |
| 728 | error = gfs2_glock_nq(ghs + x); |
| 729 | if (error) |
| 730 | goto out_gunlock; |
| 731 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 732 | |
Steven Whitehouse | d192a8e | 2011-05-05 12:35:40 +0100 | [diff] [blame] | 733 | error = -ENOENT; |
| 734 | if (ip->i_inode.i_nlink == 0) |
| 735 | goto out_gunlock; |
| 736 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 737 | /* Check out the old directory */ |
| 738 | |
| 739 | error = gfs2_unlink_ok(odip, &odentry->d_name, ip); |
| 740 | if (error) |
| 741 | goto out_gunlock; |
| 742 | |
| 743 | /* Check out the new directory */ |
| 744 | |
| 745 | if (nip) { |
| 746 | error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip); |
| 747 | if (error) |
| 748 | goto out_gunlock; |
| 749 | |
Steven Whitehouse | d192a8e | 2011-05-05 12:35:40 +0100 | [diff] [blame] | 750 | if (nip->i_inode.i_nlink == 0) { |
| 751 | error = -EAGAIN; |
| 752 | goto out_gunlock; |
| 753 | } |
| 754 | |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 755 | if (S_ISDIR(nip->i_inode.i_mode)) { |
Steven Whitehouse | ad6203f2 | 2008-11-03 13:59:19 +0000 | [diff] [blame] | 756 | if (nip->i_entries < 2) { |
Steven Whitehouse | 94fb763 | 2011-05-09 13:36:10 +0100 | [diff] [blame^] | 757 | gfs2_consist_inode(nip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 758 | error = -EIO; |
| 759 | goto out_gunlock; |
| 760 | } |
Steven Whitehouse | ad6203f2 | 2008-11-03 13:59:19 +0000 | [diff] [blame] | 761 | if (nip->i_entries > 2) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 762 | error = -ENOTEMPTY; |
| 763 | goto out_gunlock; |
| 764 | } |
| 765 | } |
| 766 | } else { |
Nick Piggin | b74c79e | 2011-01-07 17:49:58 +1100 | [diff] [blame] | 767 | error = gfs2_permission(ndir, MAY_WRITE | MAY_EXEC, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 768 | if (error) |
| 769 | goto out_gunlock; |
| 770 | |
Steven Whitehouse | dbb7cae | 2007-05-15 15:37:50 +0100 | [diff] [blame] | 771 | error = gfs2_dir_check(ndir, &ndentry->d_name, NULL); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 772 | switch (error) { |
| 773 | case -ENOENT: |
| 774 | error = 0; |
| 775 | break; |
| 776 | case 0: |
| 777 | error = -EEXIST; |
| 778 | default: |
| 779 | goto out_gunlock; |
| 780 | }; |
| 781 | |
| 782 | if (odip != ndip) { |
Steven Whitehouse | 4f56110 | 2006-11-01 14:04:17 -0500 | [diff] [blame] | 783 | if (!ndip->i_inode.i_nlink) { |
Steven Whitehouse | d192a8e | 2011-05-05 12:35:40 +0100 | [diff] [blame] | 784 | error = -ENOENT; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 785 | goto out_gunlock; |
| 786 | } |
Steven Whitehouse | ad6203f2 | 2008-11-03 13:59:19 +0000 | [diff] [blame] | 787 | if (ndip->i_entries == (u32)-1) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 788 | error = -EFBIG; |
| 789 | goto out_gunlock; |
| 790 | } |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 791 | if (S_ISDIR(ip->i_inode.i_mode) && |
Steven Whitehouse | 4f56110 | 2006-11-01 14:04:17 -0500 | [diff] [blame] | 792 | ndip->i_inode.i_nlink == (u32)-1) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 793 | error = -EMLINK; |
| 794 | goto out_gunlock; |
| 795 | } |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | /* Check out the dir to be renamed */ |
| 800 | |
| 801 | if (dir_rename) { |
Nick Piggin | b74c79e | 2011-01-07 17:49:58 +1100 | [diff] [blame] | 802 | error = gfs2_permission(odentry->d_inode, MAY_WRITE, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 803 | if (error) |
| 804 | goto out_gunlock; |
| 805 | } |
| 806 | |
Steven Whitehouse | 24b977b | 2009-12-09 13:55:12 +0000 | [diff] [blame] | 807 | if (nip == NULL) |
| 808 | alloc_required = gfs2_diradd_alloc_required(ndir, &ndentry->d_name); |
| 809 | error = alloc_required; |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 810 | if (error < 0) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 811 | goto out_gunlock; |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 812 | error = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 813 | |
| 814 | if (alloc_required) { |
| 815 | struct gfs2_alloc *al = gfs2_alloc_get(ndip); |
Cyrill Gorcunov | 182fe5a | 2008-03-03 21:54:21 +0300 | [diff] [blame] | 816 | if (!al) { |
| 817 | error = -ENOMEM; |
| 818 | goto out_gunlock; |
| 819 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 820 | |
Steven Whitehouse | d82661d | 2008-03-10 15:34:50 +0000 | [diff] [blame] | 821 | error = gfs2_quota_lock_check(ndip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 822 | if (error) |
| 823 | goto out_alloc; |
| 824 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 825 | al->al_requested = sdp->sd_max_dirres; |
| 826 | |
Bob Peterson | 46290341 | 2010-09-30 10:34:00 -0400 | [diff] [blame] | 827 | error = gfs2_inplace_reserve_ri(ndip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 828 | if (error) |
| 829 | goto out_gunlock_q; |
| 830 | |
Steven Whitehouse | fe1bded | 2006-04-18 10:09:15 -0400 | [diff] [blame] | 831 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + |
Benjamin Marzinski | bf97b67 | 2010-09-27 16:00:04 -0500 | [diff] [blame] | 832 | gfs2_rg_blocks(al) + |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 833 | 4 * RES_DINODE + 4 * RES_LEAF + |
S. Wendy Cheng | 87d21e0 | 2007-01-18 16:07:03 -0500 | [diff] [blame] | 834 | RES_STATFS + RES_QUOTA + 4, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 835 | if (error) |
| 836 | goto out_ipreserv; |
| 837 | } else { |
| 838 | error = gfs2_trans_begin(sdp, 4 * RES_DINODE + |
S. Wendy Cheng | 87d21e0 | 2007-01-18 16:07:03 -0500 | [diff] [blame] | 839 | 5 * RES_LEAF + 4, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 840 | if (error) |
| 841 | goto out_gunlock; |
| 842 | } |
| 843 | |
| 844 | /* Remove the target file, if it exists */ |
| 845 | |
| 846 | if (nip) { |
Steven Whitehouse | 855d23c | 2011-05-09 16:42:37 +0100 | [diff] [blame] | 847 | struct buffer_head *bh; |
| 848 | error = gfs2_meta_inode_buffer(nip, &bh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 849 | if (error) |
| 850 | goto out_end_trans; |
Steven Whitehouse | 855d23c | 2011-05-09 16:42:37 +0100 | [diff] [blame] | 851 | error = gfs2_unlink_inode(ndip, ndentry, bh); |
| 852 | brelse(bh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | if (dir_rename) { |
Steven Whitehouse | 8d12358 | 2010-09-17 12:30:23 +0100 | [diff] [blame] | 856 | error = gfs2_dir_mvino(ip, &gfs2_qdotdot, ndip, DT_DIR); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 857 | if (error) |
| 858 | goto out_end_trans; |
| 859 | } else { |
| 860 | struct buffer_head *dibh; |
| 861 | error = gfs2_meta_inode_buffer(ip, &dibh); |
| 862 | if (error) |
| 863 | goto out_end_trans; |
Steven Whitehouse | 4bd91ba | 2007-06-05 09:39:18 +0100 | [diff] [blame] | 864 | ip->i_inode.i_ctime = CURRENT_TIME; |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 865 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
Steven Whitehouse | 539e5d6 | 2006-10-31 15:07:05 -0500 | [diff] [blame] | 866 | gfs2_dinode_out(ip, dibh->b_data); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 867 | brelse(dibh); |
| 868 | } |
| 869 | |
Steven Whitehouse | 855d23c | 2011-05-09 16:42:37 +0100 | [diff] [blame] | 870 | error = gfs2_dir_del(odip, odentry); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 871 | if (error) |
| 872 | goto out_end_trans; |
| 873 | |
Steven Whitehouse | 3d6ecb7 | 2011-05-09 13:30:08 +0100 | [diff] [blame] | 874 | error = gfs2_dir_add(ndir, &ndentry->d_name, ip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 875 | if (error) |
| 876 | goto out_end_trans; |
| 877 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 878 | out_end_trans: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 879 | gfs2_trans_end(sdp); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 880 | out_ipreserv: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 881 | if (alloc_required) |
| 882 | gfs2_inplace_release(ndip); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 883 | out_gunlock_q: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 884 | if (alloc_required) |
| 885 | gfs2_quota_unlock(ndip); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 886 | out_alloc: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 887 | if (alloc_required) |
| 888 | gfs2_alloc_put(ndip); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 889 | out_gunlock: |
Bob Peterson | 72dbf47 | 2008-08-12 13:39:29 -0500 | [diff] [blame] | 890 | while (x--) { |
| 891 | gfs2_glock_dq(ghs + x); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 892 | gfs2_holder_uninit(ghs + x); |
Bob Peterson | 72dbf47 | 2008-08-12 13:39:29 -0500 | [diff] [blame] | 893 | } |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 894 | out_gunlock_r: |
Steven Whitehouse | 0188d6c | 2008-08-26 09:38:26 +0100 | [diff] [blame] | 895 | if (r_gh.gh_gl) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 896 | gfs2_glock_dq_uninit(&r_gh); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 897 | out: |
Bob Peterson | 46290341 | 2010-09-30 10:34:00 -0400 | [diff] [blame] | 898 | gfs2_glock_dq_uninit(&ri_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 899 | return error; |
| 900 | } |
| 901 | |
| 902 | /** |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 903 | * gfs2_follow_link - Follow a symbolic link |
| 904 | * @dentry: The dentry of the link |
| 905 | * @nd: Data that we pass to vfs_follow_link() |
| 906 | * |
Al Viro | c177c2a | 2010-01-14 00:59:16 -0500 | [diff] [blame] | 907 | * This can handle symlinks of any size. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 908 | * |
| 909 | * Returns: 0 on success or error code |
| 910 | */ |
| 911 | |
| 912 | static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd) |
| 913 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 914 | struct gfs2_inode *ip = GFS2_I(dentry->d_inode); |
Al Viro | c177c2a | 2010-01-14 00:59:16 -0500 | [diff] [blame] | 915 | struct gfs2_holder i_gh; |
| 916 | struct buffer_head *dibh; |
Steven Whitehouse | a2e0f79 | 2010-08-11 09:53:11 +0100 | [diff] [blame] | 917 | unsigned int x, size; |
Al Viro | c177c2a | 2010-01-14 00:59:16 -0500 | [diff] [blame] | 918 | char *buf; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 919 | int error; |
| 920 | |
Al Viro | c177c2a | 2010-01-14 00:59:16 -0500 | [diff] [blame] | 921 | gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh); |
| 922 | error = gfs2_glock_nq(&i_gh); |
| 923 | if (error) { |
| 924 | gfs2_holder_uninit(&i_gh); |
| 925 | nd_set_link(nd, ERR_PTR(error)); |
| 926 | return NULL; |
| 927 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 928 | |
Steven Whitehouse | a2e0f79 | 2010-08-11 09:53:11 +0100 | [diff] [blame] | 929 | size = (unsigned int)i_size_read(&ip->i_inode); |
| 930 | if (size == 0) { |
Al Viro | c177c2a | 2010-01-14 00:59:16 -0500 | [diff] [blame] | 931 | gfs2_consist_inode(ip); |
| 932 | buf = ERR_PTR(-EIO); |
| 933 | goto out; |
| 934 | } |
| 935 | |
| 936 | error = gfs2_meta_inode_buffer(ip, &dibh); |
| 937 | if (error) { |
| 938 | buf = ERR_PTR(error); |
| 939 | goto out; |
| 940 | } |
| 941 | |
Steven Whitehouse | a2e0f79 | 2010-08-11 09:53:11 +0100 | [diff] [blame] | 942 | x = size + 1; |
Al Viro | c177c2a | 2010-01-14 00:59:16 -0500 | [diff] [blame] | 943 | buf = kmalloc(x, GFP_NOFS); |
| 944 | if (!buf) |
| 945 | buf = ERR_PTR(-ENOMEM); |
| 946 | else |
| 947 | memcpy(buf, dibh->b_data + sizeof(struct gfs2_dinode), x); |
| 948 | brelse(dibh); |
| 949 | out: |
| 950 | gfs2_glock_dq_uninit(&i_gh); |
| 951 | nd_set_link(nd, buf); |
| 952 | return NULL; |
| 953 | } |
| 954 | |
| 955 | static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p) |
| 956 | { |
| 957 | char *s = nd_get_link(nd); |
| 958 | if (!IS_ERR(s)) |
| 959 | kfree(s); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | /** |
| 963 | * gfs2_permission - |
Steven Whitehouse | 75d5cfb | 2011-01-19 09:42:40 +0000 | [diff] [blame] | 964 | * @inode: The inode |
| 965 | * @mask: The mask to be tested |
| 966 | * @flags: Indicates whether this is an RCU path walk or not |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 967 | * |
Steven Whitehouse | 300c7d7 | 2006-11-27 09:55:28 -0500 | [diff] [blame] | 968 | * This may be called from the VFS directly, or from within GFS2 with the |
| 969 | * inode locked, so we look to see if the glock is already locked and only |
| 970 | * lock the glock if its not already been done. |
| 971 | * |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 972 | * Returns: errno |
| 973 | */ |
| 974 | |
Nick Piggin | b74c79e | 2011-01-07 17:49:58 +1100 | [diff] [blame] | 975 | int gfs2_permission(struct inode *inode, int mask, unsigned int flags) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 976 | { |
Nick Piggin | b74c79e | 2011-01-07 17:49:58 +1100 | [diff] [blame] | 977 | struct gfs2_inode *ip; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 978 | struct gfs2_holder i_gh; |
| 979 | int error; |
Steven Whitehouse | 300c7d7 | 2006-11-27 09:55:28 -0500 | [diff] [blame] | 980 | int unlock = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 981 | |
Nick Piggin | b74c79e | 2011-01-07 17:49:58 +1100 | [diff] [blame] | 982 | |
| 983 | ip = GFS2_I(inode); |
Steven Whitehouse | 7afd88d | 2008-02-22 16:07:18 +0000 | [diff] [blame] | 984 | if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) { |
Steven Whitehouse | 75d5cfb | 2011-01-19 09:42:40 +0000 | [diff] [blame] | 985 | if (flags & IPERM_FLAG_RCU) |
| 986 | return -ECHILD; |
Steven Whitehouse | 300c7d7 | 2006-11-27 09:55:28 -0500 | [diff] [blame] | 987 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh); |
| 988 | if (error) |
| 989 | return error; |
| 990 | unlock = 1; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 991 | } |
| 992 | |
Miklos Szeredi | f58ba88 | 2008-07-02 21:12:01 +0200 | [diff] [blame] | 993 | if ((mask & MAY_WRITE) && IS_IMMUTABLE(inode)) |
| 994 | error = -EACCES; |
| 995 | else |
Nick Piggin | b74c79e | 2011-01-07 17:49:58 +1100 | [diff] [blame] | 996 | error = generic_permission(inode, mask, flags, gfs2_check_acl); |
Steven Whitehouse | 300c7d7 | 2006-11-27 09:55:28 -0500 | [diff] [blame] | 997 | if (unlock) |
| 998 | gfs2_glock_dq_uninit(&i_gh); |
| 999 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1000 | return error; |
| 1001 | } |
| 1002 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1003 | static int setattr_chown(struct inode *inode, struct iattr *attr) |
| 1004 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1005 | struct gfs2_inode *ip = GFS2_I(inode); |
| 1006 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 1007 | u32 ouid, ogid, nuid, ngid; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1008 | int error; |
| 1009 | |
Steven Whitehouse | 2933f92 | 2006-11-01 13:23:29 -0500 | [diff] [blame] | 1010 | ouid = inode->i_uid; |
| 1011 | ogid = inode->i_gid; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1012 | nuid = attr->ia_uid; |
| 1013 | ngid = attr->ia_gid; |
| 1014 | |
| 1015 | if (!(attr->ia_valid & ATTR_UID) || ouid == nuid) |
| 1016 | ouid = nuid = NO_QUOTA_CHANGE; |
| 1017 | if (!(attr->ia_valid & ATTR_GID) || ogid == ngid) |
| 1018 | ogid = ngid = NO_QUOTA_CHANGE; |
| 1019 | |
Cyrill Gorcunov | 182fe5a | 2008-03-03 21:54:21 +0300 | [diff] [blame] | 1020 | if (!gfs2_alloc_get(ip)) |
| 1021 | return -ENOMEM; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1022 | |
| 1023 | error = gfs2_quota_lock(ip, nuid, ngid); |
| 1024 | if (error) |
| 1025 | goto out_alloc; |
| 1026 | |
| 1027 | if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) { |
| 1028 | error = gfs2_quota_check(ip, nuid, ngid); |
| 1029 | if (error) |
| 1030 | goto out_gunlock_q; |
| 1031 | } |
| 1032 | |
| 1033 | error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0); |
| 1034 | if (error) |
| 1035 | goto out_gunlock_q; |
| 1036 | |
Steven Whitehouse | 2ae51ed | 2010-11-10 15:14:57 +0000 | [diff] [blame] | 1037 | error = gfs2_setattr_simple(ip, attr); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1038 | if (error) |
| 1039 | goto out_end_trans; |
| 1040 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1041 | if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) { |
Steven Whitehouse | 77658aa | 2008-02-12 14:17:27 +0000 | [diff] [blame] | 1042 | u64 blocks = gfs2_get_inode_blocks(&ip->i_inode); |
| 1043 | gfs2_quota_change(ip, -blocks, ouid, ogid); |
| 1044 | gfs2_quota_change(ip, blocks, nuid, ngid); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1047 | out_end_trans: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1048 | gfs2_trans_end(sdp); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1049 | out_gunlock_q: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1050 | gfs2_quota_unlock(ip); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1051 | out_alloc: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1052 | gfs2_alloc_put(ip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1053 | return error; |
| 1054 | } |
| 1055 | |
| 1056 | /** |
| 1057 | * gfs2_setattr - Change attributes on an inode |
| 1058 | * @dentry: The dentry which is changing |
| 1059 | * @attr: The structure describing the change |
| 1060 | * |
| 1061 | * The VFS layer wants to change one or more of an inodes attributes. Write |
| 1062 | * that change out to disk. |
| 1063 | * |
| 1064 | * Returns: errno |
| 1065 | */ |
| 1066 | |
| 1067 | static int gfs2_setattr(struct dentry *dentry, struct iattr *attr) |
| 1068 | { |
| 1069 | struct inode *inode = dentry->d_inode; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1070 | struct gfs2_inode *ip = GFS2_I(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1071 | struct gfs2_holder i_gh; |
| 1072 | int error; |
| 1073 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1074 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); |
| 1075 | if (error) |
| 1076 | return error; |
| 1077 | |
| 1078 | error = -EPERM; |
| 1079 | if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
| 1080 | goto out; |
| 1081 | |
| 1082 | error = inode_change_ok(inode, attr); |
| 1083 | if (error) |
| 1084 | goto out; |
| 1085 | |
| 1086 | if (attr->ia_valid & ATTR_SIZE) |
Steven Whitehouse | ff8f33c | 2010-08-11 09:37:53 +0100 | [diff] [blame] | 1087 | error = gfs2_setattr_size(inode, attr->ia_size); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1088 | else if (attr->ia_valid & (ATTR_UID | ATTR_GID)) |
| 1089 | error = setattr_chown(inode, attr); |
| 1090 | else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode)) |
| 1091 | error = gfs2_acl_chmod(ip, attr); |
| 1092 | else |
| 1093 | error = gfs2_setattr_simple(ip, attr); |
| 1094 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1095 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1096 | gfs2_glock_dq_uninit(&i_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1097 | if (!error) |
| 1098 | mark_inode_dirty(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1099 | return error; |
| 1100 | } |
| 1101 | |
| 1102 | /** |
| 1103 | * gfs2_getattr - Read out an inode's attributes |
Steven Whitehouse | 26c1a57 | 2006-09-04 15:32:10 -0400 | [diff] [blame] | 1104 | * @mnt: The vfsmount the inode is being accessed from |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1105 | * @dentry: The dentry to stat |
| 1106 | * @stat: The inode's stats |
| 1107 | * |
Steven Whitehouse | dcf3dd8 | 2006-11-27 10:12:05 -0500 | [diff] [blame] | 1108 | * This may be called from the VFS directly, or from within GFS2 with the |
| 1109 | * inode locked, so we look to see if the glock is already locked and only |
| 1110 | * lock the glock if its not already been done. Note that its the NFS |
| 1111 | * readdirplus operation which causes this to be called (from filldir) |
| 1112 | * with the glock already held. |
| 1113 | * |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1114 | * Returns: errno |
| 1115 | */ |
| 1116 | |
| 1117 | static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, |
| 1118 | struct kstat *stat) |
| 1119 | { |
| 1120 | struct inode *inode = dentry->d_inode; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1121 | struct gfs2_inode *ip = GFS2_I(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1122 | struct gfs2_holder gh; |
| 1123 | int error; |
Steven Whitehouse | dcf3dd8 | 2006-11-27 10:12:05 -0500 | [diff] [blame] | 1124 | int unlock = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1125 | |
Steven Whitehouse | 7afd88d | 2008-02-22 16:07:18 +0000 | [diff] [blame] | 1126 | if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) { |
Steven Whitehouse | dcf3dd8 | 2006-11-27 10:12:05 -0500 | [diff] [blame] | 1127 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh); |
| 1128 | if (error) |
| 1129 | return error; |
| 1130 | unlock = 1; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |
Steven Whitehouse | dcf3dd8 | 2006-11-27 10:12:05 -0500 | [diff] [blame] | 1133 | generic_fillattr(inode, stat); |
Steven Whitehouse | d7c103d | 2007-01-25 17:14:59 +0000 | [diff] [blame] | 1134 | if (unlock) |
Steven Whitehouse | dcf3dd8 | 2006-11-27 10:12:05 -0500 | [diff] [blame] | 1135 | gfs2_glock_dq_uninit(&gh); |
| 1136 | |
| 1137 | return 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | static int gfs2_setxattr(struct dentry *dentry, const char *name, |
| 1141 | const void *data, size_t size, int flags) |
| 1142 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1143 | struct inode *inode = dentry->d_inode; |
Steven Whitehouse | 40b78a3 | 2009-08-26 18:41:32 +0100 | [diff] [blame] | 1144 | struct gfs2_inode *ip = GFS2_I(inode); |
| 1145 | struct gfs2_holder gh; |
| 1146 | int ret; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1147 | |
Steven Whitehouse | 40b78a3 | 2009-08-26 18:41:32 +0100 | [diff] [blame] | 1148 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
| 1149 | ret = gfs2_glock_nq(&gh); |
| 1150 | if (ret == 0) { |
| 1151 | ret = generic_setxattr(dentry, name, data, size, flags); |
| 1152 | gfs2_glock_dq(&gh); |
| 1153 | } |
| 1154 | gfs2_holder_uninit(&gh); |
| 1155 | return ret; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name, |
| 1159 | void *data, size_t size) |
| 1160 | { |
Steven Whitehouse | 40b78a3 | 2009-08-26 18:41:32 +0100 | [diff] [blame] | 1161 | struct inode *inode = dentry->d_inode; |
| 1162 | struct gfs2_inode *ip = GFS2_I(inode); |
| 1163 | struct gfs2_holder gh; |
| 1164 | int ret; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1165 | |
Steven Whitehouse | 40b78a3 | 2009-08-26 18:41:32 +0100 | [diff] [blame] | 1166 | gfs2_holder_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh); |
| 1167 | ret = gfs2_glock_nq(&gh); |
| 1168 | if (ret == 0) { |
| 1169 | ret = generic_getxattr(dentry, name, data, size); |
| 1170 | gfs2_glock_dq(&gh); |
| 1171 | } |
| 1172 | gfs2_holder_uninit(&gh); |
| 1173 | return ret; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | static int gfs2_removexattr(struct dentry *dentry, const char *name) |
| 1177 | { |
Steven Whitehouse | 40b78a3 | 2009-08-26 18:41:32 +0100 | [diff] [blame] | 1178 | struct inode *inode = dentry->d_inode; |
| 1179 | struct gfs2_inode *ip = GFS2_I(inode); |
| 1180 | struct gfs2_holder gh; |
| 1181 | int ret; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1182 | |
Steven Whitehouse | 40b78a3 | 2009-08-26 18:41:32 +0100 | [diff] [blame] | 1183 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
| 1184 | ret = gfs2_glock_nq(&gh); |
| 1185 | if (ret == 0) { |
| 1186 | ret = generic_removexattr(dentry, name); |
| 1187 | gfs2_glock_dq(&gh); |
| 1188 | } |
| 1189 | gfs2_holder_uninit(&gh); |
| 1190 | return ret; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1191 | } |
| 1192 | |
Steven Whitehouse | e9079cc | 2008-10-14 14:43:29 +0100 | [diff] [blame] | 1193 | static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, |
| 1194 | u64 start, u64 len) |
| 1195 | { |
| 1196 | struct gfs2_inode *ip = GFS2_I(inode); |
| 1197 | struct gfs2_holder gh; |
| 1198 | int ret; |
| 1199 | |
| 1200 | ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC); |
| 1201 | if (ret) |
| 1202 | return ret; |
| 1203 | |
| 1204 | mutex_lock(&inode->i_mutex); |
| 1205 | |
| 1206 | ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh); |
| 1207 | if (ret) |
| 1208 | goto out; |
| 1209 | |
| 1210 | if (gfs2_is_stuffed(ip)) { |
| 1211 | u64 phys = ip->i_no_addr << inode->i_blkbits; |
| 1212 | u64 size = i_size_read(inode); |
| 1213 | u32 flags = FIEMAP_EXTENT_LAST|FIEMAP_EXTENT_NOT_ALIGNED| |
| 1214 | FIEMAP_EXTENT_DATA_INLINE; |
| 1215 | phys += sizeof(struct gfs2_dinode); |
| 1216 | phys += start; |
| 1217 | if (start + len > size) |
| 1218 | len = size - start; |
| 1219 | if (start < size) |
| 1220 | ret = fiemap_fill_next_extent(fieinfo, start, phys, |
| 1221 | len, flags); |
| 1222 | if (ret == 1) |
| 1223 | ret = 0; |
| 1224 | } else { |
| 1225 | ret = __generic_block_fiemap(inode, fieinfo, start, len, |
| 1226 | gfs2_block_map); |
| 1227 | } |
| 1228 | |
| 1229 | gfs2_glock_dq_uninit(&gh); |
| 1230 | out: |
| 1231 | mutex_unlock(&inode->i_mutex); |
| 1232 | return ret; |
| 1233 | } |
| 1234 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 1235 | const struct inode_operations gfs2_file_iops = { |
Al Viro | e6305c4 | 2008-07-15 21:03:57 -0400 | [diff] [blame] | 1236 | .permission = gfs2_permission, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1237 | .setattr = gfs2_setattr, |
| 1238 | .getattr = gfs2_getattr, |
| 1239 | .setxattr = gfs2_setxattr, |
| 1240 | .getxattr = gfs2_getxattr, |
| 1241 | .listxattr = gfs2_listxattr, |
| 1242 | .removexattr = gfs2_removexattr, |
Steven Whitehouse | e9079cc | 2008-10-14 14:43:29 +0100 | [diff] [blame] | 1243 | .fiemap = gfs2_fiemap, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1244 | }; |
| 1245 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 1246 | const struct inode_operations gfs2_dir_iops = { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1247 | .create = gfs2_create, |
| 1248 | .lookup = gfs2_lookup, |
| 1249 | .link = gfs2_link, |
| 1250 | .unlink = gfs2_unlink, |
| 1251 | .symlink = gfs2_symlink, |
| 1252 | .mkdir = gfs2_mkdir, |
Steven Whitehouse | 855d23c | 2011-05-09 16:42:37 +0100 | [diff] [blame] | 1253 | .rmdir = gfs2_unlink, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1254 | .mknod = gfs2_mknod, |
| 1255 | .rename = gfs2_rename, |
Al Viro | e6305c4 | 2008-07-15 21:03:57 -0400 | [diff] [blame] | 1256 | .permission = gfs2_permission, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1257 | .setattr = gfs2_setattr, |
| 1258 | .getattr = gfs2_getattr, |
| 1259 | .setxattr = gfs2_setxattr, |
| 1260 | .getxattr = gfs2_getxattr, |
| 1261 | .listxattr = gfs2_listxattr, |
| 1262 | .removexattr = gfs2_removexattr, |
Steven Whitehouse | e9079cc | 2008-10-14 14:43:29 +0100 | [diff] [blame] | 1263 | .fiemap = gfs2_fiemap, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1264 | }; |
| 1265 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 1266 | const struct inode_operations gfs2_symlink_iops = { |
Al Viro | c177c2a | 2010-01-14 00:59:16 -0500 | [diff] [blame] | 1267 | .readlink = generic_readlink, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1268 | .follow_link = gfs2_follow_link, |
Al Viro | c177c2a | 2010-01-14 00:59:16 -0500 | [diff] [blame] | 1269 | .put_link = gfs2_put_link, |
Al Viro | e6305c4 | 2008-07-15 21:03:57 -0400 | [diff] [blame] | 1270 | .permission = gfs2_permission, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1271 | .setattr = gfs2_setattr, |
| 1272 | .getattr = gfs2_getattr, |
| 1273 | .setxattr = gfs2_setxattr, |
| 1274 | .getxattr = gfs2_getxattr, |
| 1275 | .listxattr = gfs2_listxattr, |
| 1276 | .removexattr = gfs2_removexattr, |
Steven Whitehouse | e9079cc | 2008-10-14 14:43:29 +0100 | [diff] [blame] | 1277 | .fiemap = gfs2_fiemap, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1278 | }; |
| 1279 | |