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 | |
| 10 | #include <linux/sched.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/spinlock.h> |
| 13 | #include <linux/completion.h> |
| 14 | #include <linux/buffer_head.h> |
| 15 | #include <linux/namei.h> |
| 16 | #include <linux/utsname.h> |
| 17 | #include <linux/mm.h> |
| 18 | #include <linux/xattr.h> |
| 19 | #include <linux/posix_acl.h> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 20 | #include <linux/gfs2_ondisk.h> |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 21 | #include <linux/crc32.h> |
Fabio Massimo Di Nitto | 7d30859 | 2006-09-19 07:56:29 +0200 | [diff] [blame] | 22 | #include <linux/lm_interface.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 23 | #include <asm/uaccess.h> |
| 24 | |
| 25 | #include "gfs2.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 26 | #include "incore.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 27 | #include "acl.h" |
| 28 | #include "bmap.h" |
| 29 | #include "dir.h" |
| 30 | #include "eaops.h" |
| 31 | #include "eattr.h" |
| 32 | #include "glock.h" |
| 33 | #include "inode.h" |
| 34 | #include "meta_io.h" |
| 35 | #include "ops_dentry.h" |
| 36 | #include "ops_inode.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 37 | #include "quota.h" |
| 38 | #include "rgrp.h" |
| 39 | #include "trans.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 40 | #include "util.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * gfs2_create - Create a file |
| 44 | * @dir: The directory in which to create the file |
| 45 | * @dentry: The dentry of the new file |
| 46 | * @mode: The mode of the new file |
| 47 | * |
| 48 | * Returns: errno |
| 49 | */ |
| 50 | |
| 51 | static int gfs2_create(struct inode *dir, struct dentry *dentry, |
| 52 | int mode, struct nameidata *nd) |
| 53 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 54 | struct gfs2_inode *dip = GFS2_I(dir); |
| 55 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 56 | struct gfs2_holder ghs[2]; |
| 57 | struct inode *inode; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 58 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 59 | gfs2_holder_init(dip->i_gl, 0, 0, ghs); |
| 60 | |
| 61 | for (;;) { |
Steven Whitehouse | e7f14f4 | 2006-10-31 21:45:08 -0500 | [diff] [blame] | 62 | inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode, 0); |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 63 | if (!IS_ERR(inode)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 64 | gfs2_trans_end(sdp); |
| 65 | if (dip->i_alloc.al_rgd) |
| 66 | gfs2_inplace_release(dip); |
| 67 | gfs2_quota_unlock(dip); |
| 68 | gfs2_alloc_put(dip); |
| 69 | gfs2_glock_dq_uninit_m(2, ghs); |
Steven Whitehouse | 3a8476d | 2006-06-19 09:10:39 -0400 | [diff] [blame] | 70 | mark_inode_dirty(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 71 | break; |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 72 | } else if (PTR_ERR(inode) != -EEXIST || |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 73 | (nd->intent.open.flags & O_EXCL)) { |
| 74 | gfs2_holder_uninit(ghs); |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 75 | return PTR_ERR(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 78 | inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd); |
| 79 | if (inode) { |
| 80 | if (!IS_ERR(inode)) { |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 81 | gfs2_holder_uninit(ghs); |
| 82 | break; |
| 83 | } else { |
| 84 | gfs2_holder_uninit(ghs); |
| 85 | return PTR_ERR(inode); |
| 86 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 90 | d_instantiate(dentry, inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * gfs2_lookup - Look up a filename in a directory and return its inode |
| 97 | * @dir: The directory inode |
| 98 | * @dentry: The dentry of the new inode |
| 99 | * @nd: passed from Linux VFS, ignored by us |
| 100 | * |
| 101 | * Called by the VFS layer. Lock dir and call gfs2_lookupi() |
| 102 | * |
| 103 | * Returns: errno |
| 104 | */ |
| 105 | |
| 106 | static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry, |
| 107 | struct nameidata *nd) |
| 108 | { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 109 | struct inode *inode = NULL; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 110 | |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 111 | dentry->d_op = &gfs2_dops; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 112 | |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 113 | inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd); |
| 114 | if (inode && IS_ERR(inode)) |
| 115 | return ERR_PTR(PTR_ERR(inode)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 116 | |
| 117 | if (inode) |
| 118 | return d_splice_alias(inode, dentry); |
| 119 | d_add(dentry, inode); |
| 120 | |
| 121 | return NULL; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * gfs2_link - Link to a file |
| 126 | * @old_dentry: The inode to link |
| 127 | * @dir: Add link to this directory |
| 128 | * @dentry: The name of the link |
| 129 | * |
| 130 | * Link the inode in "old_dentry" into the directory "dir" with the |
| 131 | * name in "dentry". |
| 132 | * |
| 133 | * Returns: errno |
| 134 | */ |
| 135 | |
| 136 | static int gfs2_link(struct dentry *old_dentry, struct inode *dir, |
| 137 | struct dentry *dentry) |
| 138 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 139 | struct gfs2_inode *dip = GFS2_I(dir); |
| 140 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 141 | struct inode *inode = old_dentry->d_inode; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 142 | struct gfs2_inode *ip = GFS2_I(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 143 | struct gfs2_holder ghs[2]; |
| 144 | int alloc_required; |
| 145 | int error; |
| 146 | |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 147 | if (S_ISDIR(inode->i_mode)) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 148 | return -EPERM; |
| 149 | |
| 150 | gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); |
| 151 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); |
| 152 | |
| 153 | error = gfs2_glock_nq_m(2, ghs); |
| 154 | if (error) |
| 155 | goto out; |
| 156 | |
Steven Whitehouse | faf450e | 2006-06-22 10:59:10 -0400 | [diff] [blame] | 157 | error = permission(dir, MAY_WRITE | MAY_EXEC, NULL); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 158 | if (error) |
| 159 | goto out_gunlock; |
| 160 | |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 161 | error = gfs2_dir_search(dir, &dentry->d_name, NULL, NULL); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 162 | switch (error) { |
| 163 | case -ENOENT: |
| 164 | break; |
| 165 | case 0: |
| 166 | error = -EEXIST; |
| 167 | default: |
| 168 | goto out_gunlock; |
| 169 | } |
| 170 | |
| 171 | error = -EINVAL; |
Steven Whitehouse | 4f56110 | 2006-11-01 14:04:17 -0500 | [diff] [blame] | 172 | if (!dip->i_inode.i_nlink) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 173 | goto out_gunlock; |
| 174 | error = -EFBIG; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 175 | if (dip->i_di.di_entries == (u32)-1) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 176 | goto out_gunlock; |
| 177 | error = -EPERM; |
| 178 | if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
| 179 | goto out_gunlock; |
| 180 | error = -EINVAL; |
Steven Whitehouse | 4f56110 | 2006-11-01 14:04:17 -0500 | [diff] [blame] | 181 | if (!ip->i_inode.i_nlink) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 182 | goto out_gunlock; |
| 183 | error = -EMLINK; |
Steven Whitehouse | 4f56110 | 2006-11-01 14:04:17 -0500 | [diff] [blame] | 184 | if (ip->i_inode.i_nlink == (u32)-1) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 185 | goto out_gunlock; |
| 186 | |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 187 | alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name); |
| 188 | if (error < 0) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 189 | goto out_gunlock; |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 190 | error = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 191 | |
| 192 | if (alloc_required) { |
| 193 | struct gfs2_alloc *al = gfs2_alloc_get(dip); |
| 194 | |
| 195 | error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); |
| 196 | if (error) |
| 197 | goto out_alloc; |
| 198 | |
Steven Whitehouse | 2933f92 | 2006-11-01 13:23:29 -0500 | [diff] [blame] | 199 | error = gfs2_quota_check(dip, dip->i_inode.i_uid, dip->i_inode.i_gid); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 200 | if (error) |
| 201 | goto out_gunlock_q; |
| 202 | |
| 203 | al->al_requested = sdp->sd_max_dirres; |
| 204 | |
| 205 | error = gfs2_inplace_reserve(dip); |
| 206 | if (error) |
| 207 | goto out_gunlock_q; |
| 208 | |
Steven Whitehouse | 1b50259 | 2006-05-18 14:10:52 -0400 | [diff] [blame] | 209 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 210 | al->al_rgd->rd_ri.ri_length + |
| 211 | 2 * RES_DINODE + RES_STATFS + |
| 212 | RES_QUOTA, 0); |
| 213 | if (error) |
| 214 | goto out_ipres; |
| 215 | } else { |
| 216 | error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0); |
| 217 | if (error) |
| 218 | goto out_ipres; |
| 219 | } |
| 220 | |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 221 | error = gfs2_dir_add(dir, &dentry->d_name, &ip->i_num, |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 222 | IF2DT(inode->i_mode)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 223 | if (error) |
| 224 | goto out_end_trans; |
| 225 | |
| 226 | error = gfs2_change_nlink(ip, +1); |
| 227 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 228 | out_end_trans: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 229 | gfs2_trans_end(sdp); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 230 | out_ipres: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 231 | if (alloc_required) |
| 232 | gfs2_inplace_release(dip); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 233 | out_gunlock_q: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 234 | if (alloc_required) |
| 235 | gfs2_quota_unlock(dip); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 236 | out_alloc: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 237 | if (alloc_required) |
| 238 | gfs2_alloc_put(dip); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 239 | out_gunlock: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 240 | gfs2_glock_dq_m(2, ghs); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 241 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 242 | gfs2_holder_uninit(ghs); |
| 243 | gfs2_holder_uninit(ghs + 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 244 | if (!error) { |
Steven Whitehouse | 29937ac | 2006-07-06 17:58:03 -0400 | [diff] [blame] | 245 | atomic_inc(&inode->i_count); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 246 | d_instantiate(dentry, inode); |
| 247 | mark_inode_dirty(inode); |
| 248 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 249 | return error; |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * gfs2_unlink - Unlink a file |
| 254 | * @dir: The inode of the directory containing the file to unlink |
| 255 | * @dentry: The file itself |
| 256 | * |
| 257 | * Unlink a file. Call gfs2_unlinki() |
| 258 | * |
| 259 | * Returns: errno |
| 260 | */ |
| 261 | |
| 262 | static int gfs2_unlink(struct inode *dir, struct dentry *dentry) |
| 263 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 264 | struct gfs2_inode *dip = GFS2_I(dir); |
| 265 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
| 266 | struct gfs2_inode *ip = GFS2_I(dentry->d_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 267 | struct gfs2_holder ghs[2]; |
| 268 | int error; |
| 269 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 270 | gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); |
| 271 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); |
| 272 | |
| 273 | error = gfs2_glock_nq_m(2, ghs); |
| 274 | if (error) |
| 275 | goto out; |
| 276 | |
| 277 | error = gfs2_unlink_ok(dip, &dentry->d_name, ip); |
| 278 | if (error) |
| 279 | goto out_gunlock; |
| 280 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 281 | error = gfs2_trans_begin(sdp, 2*RES_DINODE + RES_LEAF + RES_RG_BIT, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 282 | if (error) |
| 283 | goto out_gunlock; |
| 284 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 285 | error = gfs2_dir_del(dip, &dentry->d_name); |
| 286 | if (error) |
| 287 | goto out_end_trans; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 288 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 289 | error = gfs2_change_nlink(ip, -1); |
| 290 | |
| 291 | out_end_trans: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 292 | gfs2_trans_end(sdp); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 293 | out_gunlock: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 294 | gfs2_glock_dq_m(2, ghs); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 295 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 296 | gfs2_holder_uninit(ghs); |
| 297 | gfs2_holder_uninit(ghs + 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 298 | return error; |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * gfs2_symlink - Create a symlink |
| 303 | * @dir: The directory to create the symlink in |
| 304 | * @dentry: The dentry to put the symlink in |
| 305 | * @symname: The thing which the link points to |
| 306 | * |
| 307 | * Returns: errno |
| 308 | */ |
| 309 | |
| 310 | static int gfs2_symlink(struct inode *dir, struct dentry *dentry, |
| 311 | const char *symname) |
| 312 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 313 | struct gfs2_inode *dip = GFS2_I(dir), *ip; |
| 314 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 315 | struct gfs2_holder ghs[2]; |
| 316 | struct inode *inode; |
| 317 | struct buffer_head *dibh; |
| 318 | int size; |
| 319 | int error; |
| 320 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 321 | /* Must be stuffed with a null terminator for gfs2_follow_link() */ |
| 322 | size = strlen(symname); |
| 323 | if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1) |
| 324 | return -ENAMETOOLONG; |
| 325 | |
| 326 | gfs2_holder_init(dip->i_gl, 0, 0, ghs); |
| 327 | |
Steven Whitehouse | e7f14f4 | 2006-10-31 21:45:08 -0500 | [diff] [blame] | 328 | inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO, 0); |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 329 | if (IS_ERR(inode)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 330 | gfs2_holder_uninit(ghs); |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 331 | return PTR_ERR(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 334 | ip = ghs[1].gh_gl->gl_object; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 335 | |
| 336 | ip->i_di.di_size = size; |
| 337 | |
| 338 | error = gfs2_meta_inode_buffer(ip, &dibh); |
| 339 | |
| 340 | if (!gfs2_assert_withdraw(sdp, !error)) { |
Steven Whitehouse | 539e5d6 | 2006-10-31 15:07:05 -0500 | [diff] [blame] | 341 | gfs2_dinode_out(ip, dibh->b_data); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 342 | memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname, |
| 343 | size); |
| 344 | brelse(dibh); |
| 345 | } |
| 346 | |
| 347 | gfs2_trans_end(sdp); |
| 348 | if (dip->i_alloc.al_rgd) |
| 349 | gfs2_inplace_release(dip); |
| 350 | gfs2_quota_unlock(dip); |
| 351 | gfs2_alloc_put(dip); |
| 352 | |
| 353 | gfs2_glock_dq_uninit_m(2, ghs); |
| 354 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 355 | d_instantiate(dentry, inode); |
| 356 | mark_inode_dirty(inode); |
| 357 | |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | /** |
| 362 | * gfs2_mkdir - Make a directory |
| 363 | * @dir: The parent directory of the new one |
| 364 | * @dentry: The dentry of the new directory |
| 365 | * @mode: The mode of the new directory |
| 366 | * |
| 367 | * Returns: errno |
| 368 | */ |
| 369 | |
| 370 | static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode) |
| 371 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 372 | struct gfs2_inode *dip = GFS2_I(dir), *ip; |
| 373 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 374 | struct gfs2_holder ghs[2]; |
| 375 | struct inode *inode; |
| 376 | struct buffer_head *dibh; |
| 377 | int error; |
| 378 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 379 | gfs2_holder_init(dip->i_gl, 0, 0, ghs); |
| 380 | |
Steven Whitehouse | e7f14f4 | 2006-10-31 21:45:08 -0500 | [diff] [blame] | 381 | inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode, 0); |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 382 | if (IS_ERR(inode)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 383 | gfs2_holder_uninit(ghs); |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 384 | return PTR_ERR(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 387 | ip = ghs[1].gh_gl->gl_object; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 388 | |
Steven Whitehouse | 4f56110 | 2006-11-01 14:04:17 -0500 | [diff] [blame] | 389 | ip->i_inode.i_nlink = 2; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 390 | ip->i_di.di_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode); |
| 391 | ip->i_di.di_flags |= GFS2_DIF_JDATA; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 392 | ip->i_di.di_entries = 2; |
| 393 | |
| 394 | error = gfs2_meta_inode_buffer(ip, &dibh); |
| 395 | |
| 396 | if (!gfs2_assert_withdraw(sdp, !error)) { |
| 397 | struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data; |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 398 | struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1); |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 399 | struct qstr str; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 400 | |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 401 | gfs2_str2qstr(&str, "."); |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 402 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
| 403 | gfs2_qstr2dirent(&str, GFS2_DIRENT_SIZE(str.len), dent); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 404 | dent->de_inum = di->di_num; /* already GFS2 endian */ |
Steven Whitehouse | 7ecdb70 | 2006-10-03 21:03:35 -0400 | [diff] [blame] | 405 | dent->de_type = cpu_to_be16(DT_DIR); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 406 | di->di_entries = cpu_to_be32(1); |
| 407 | |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 408 | gfs2_str2qstr(&str, ".."); |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 409 | dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1)); |
| 410 | gfs2_qstr2dirent(&str, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 411 | |
Steven Whitehouse | 409e185 | 2006-10-02 14:20:43 -0400 | [diff] [blame] | 412 | gfs2_inum_out(&dip->i_num, &dent->de_inum); |
Steven Whitehouse | 7ecdb70 | 2006-10-03 21:03:35 -0400 | [diff] [blame] | 413 | dent->de_type = cpu_to_be16(DT_DIR); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 414 | |
Steven Whitehouse | 539e5d6 | 2006-10-31 15:07:05 -0500 | [diff] [blame] | 415 | gfs2_dinode_out(ip, di); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 416 | |
| 417 | brelse(dibh); |
| 418 | } |
| 419 | |
| 420 | error = gfs2_change_nlink(dip, +1); |
| 421 | gfs2_assert_withdraw(sdp, !error); /* dip already pinned */ |
| 422 | |
| 423 | gfs2_trans_end(sdp); |
| 424 | if (dip->i_alloc.al_rgd) |
| 425 | gfs2_inplace_release(dip); |
| 426 | gfs2_quota_unlock(dip); |
| 427 | gfs2_alloc_put(dip); |
| 428 | |
| 429 | gfs2_glock_dq_uninit_m(2, ghs); |
| 430 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 431 | d_instantiate(dentry, inode); |
| 432 | mark_inode_dirty(inode); |
| 433 | |
| 434 | return 0; |
| 435 | } |
| 436 | |
| 437 | /** |
| 438 | * gfs2_rmdir - Remove a directory |
| 439 | * @dir: The parent directory of the directory to be removed |
| 440 | * @dentry: The dentry of the directory to remove |
| 441 | * |
| 442 | * Remove a directory. Call gfs2_rmdiri() |
| 443 | * |
| 444 | * Returns: errno |
| 445 | */ |
| 446 | |
| 447 | static int gfs2_rmdir(struct inode *dir, struct dentry *dentry) |
| 448 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 449 | struct gfs2_inode *dip = GFS2_I(dir); |
| 450 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
| 451 | struct gfs2_inode *ip = GFS2_I(dentry->d_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 452 | struct gfs2_holder ghs[2]; |
| 453 | int error; |
| 454 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 455 | gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); |
| 456 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); |
| 457 | |
| 458 | error = gfs2_glock_nq_m(2, ghs); |
| 459 | if (error) |
| 460 | goto out; |
| 461 | |
| 462 | error = gfs2_unlink_ok(dip, &dentry->d_name, ip); |
| 463 | if (error) |
| 464 | goto out_gunlock; |
| 465 | |
| 466 | if (ip->i_di.di_entries < 2) { |
| 467 | if (gfs2_consist_inode(ip)) |
Steven Whitehouse | 4cc14f0 | 2006-10-31 19:00:24 -0500 | [diff] [blame] | 468 | gfs2_dinode_print(ip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 469 | error = -EIO; |
| 470 | goto out_gunlock; |
| 471 | } |
| 472 | if (ip->i_di.di_entries > 2) { |
| 473 | error = -ENOTEMPTY; |
| 474 | goto out_gunlock; |
| 475 | } |
| 476 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 477 | 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] | 478 | if (error) |
| 479 | goto out_gunlock; |
| 480 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 481 | error = gfs2_rmdiri(dip, &dentry->d_name, ip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 482 | |
| 483 | gfs2_trans_end(sdp); |
| 484 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 485 | out_gunlock: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 486 | gfs2_glock_dq_m(2, ghs); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 487 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 488 | gfs2_holder_uninit(ghs); |
| 489 | gfs2_holder_uninit(ghs + 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 490 | return error; |
| 491 | } |
| 492 | |
| 493 | /** |
| 494 | * gfs2_mknod - Make a special file |
| 495 | * @dir: The directory in which the special file will reside |
| 496 | * @dentry: The dentry of the special file |
| 497 | * @mode: The mode of the special file |
| 498 | * @rdev: The device specification of the special file |
| 499 | * |
| 500 | */ |
| 501 | |
| 502 | static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode, |
| 503 | dev_t dev) |
| 504 | { |
Steven Whitehouse | e7f14f4 | 2006-10-31 21:45:08 -0500 | [diff] [blame] | 505 | struct gfs2_inode *dip = GFS2_I(dir); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 506 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 507 | struct gfs2_holder ghs[2]; |
| 508 | struct inode *inode; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 509 | |
| 510 | gfs2_holder_init(dip->i_gl, 0, 0, ghs); |
| 511 | |
Steven Whitehouse | e7f14f4 | 2006-10-31 21:45:08 -0500 | [diff] [blame] | 512 | inode = gfs2_createi(ghs, &dentry->d_name, mode, dev); |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 513 | if (IS_ERR(inode)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 514 | gfs2_holder_uninit(ghs); |
Steven Whitehouse | 7359a19 | 2006-02-13 12:27:43 +0000 | [diff] [blame] | 515 | return PTR_ERR(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 516 | } |
| 517 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 518 | gfs2_trans_end(sdp); |
| 519 | if (dip->i_alloc.al_rgd) |
| 520 | gfs2_inplace_release(dip); |
| 521 | gfs2_quota_unlock(dip); |
| 522 | gfs2_alloc_put(dip); |
| 523 | |
| 524 | gfs2_glock_dq_uninit_m(2, ghs); |
| 525 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 526 | d_instantiate(dentry, inode); |
| 527 | mark_inode_dirty(inode); |
| 528 | |
| 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | /** |
| 533 | * gfs2_rename - Rename a file |
| 534 | * @odir: Parent directory of old file name |
| 535 | * @odentry: The old dentry of the file |
| 536 | * @ndir: Parent directory of new file name |
| 537 | * @ndentry: The new dentry of the file |
| 538 | * |
| 539 | * Returns: errno |
| 540 | */ |
| 541 | |
| 542 | static int gfs2_rename(struct inode *odir, struct dentry *odentry, |
| 543 | struct inode *ndir, struct dentry *ndentry) |
| 544 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 545 | struct gfs2_inode *odip = GFS2_I(odir); |
| 546 | struct gfs2_inode *ndip = GFS2_I(ndir); |
| 547 | struct gfs2_inode *ip = GFS2_I(odentry->d_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 548 | struct gfs2_inode *nip = NULL; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 549 | struct gfs2_sbd *sdp = GFS2_SB(odir); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 550 | struct gfs2_holder ghs[4], r_gh; |
| 551 | unsigned int num_gh; |
| 552 | int dir_rename = 0; |
| 553 | int alloc_required; |
| 554 | unsigned int x; |
| 555 | int error; |
| 556 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 557 | if (ndentry->d_inode) { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 558 | nip = GFS2_I(ndentry->d_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 559 | if (ip == nip) |
| 560 | return 0; |
| 561 | } |
| 562 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 563 | /* Make sure we aren't trying to move a dirctory into it's subdir */ |
| 564 | |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 565 | if (S_ISDIR(ip->i_inode.i_mode) && odip != ndip) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 566 | dir_rename = 1; |
| 567 | |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 568 | error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE, 0, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 569 | &r_gh); |
| 570 | if (error) |
| 571 | goto out; |
| 572 | |
| 573 | error = gfs2_ok_to_move(ip, ndip); |
| 574 | if (error) |
| 575 | goto out_gunlock_r; |
| 576 | } |
| 577 | |
Steven Whitehouse | d9d1ca3 | 2006-06-21 15:38:17 -0400 | [diff] [blame] | 578 | num_gh = 1; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 579 | gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); |
Steven Whitehouse | d9d1ca3 | 2006-06-21 15:38:17 -0400 | [diff] [blame] | 580 | if (odip != ndip) { |
| 581 | gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); |
| 582 | num_gh++; |
| 583 | } |
| 584 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); |
| 585 | num_gh++; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 586 | |
Steven Whitehouse | d9d1ca3 | 2006-06-21 15:38:17 -0400 | [diff] [blame] | 587 | if (nip) { |
| 588 | gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); |
| 589 | num_gh++; |
| 590 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 591 | |
| 592 | error = gfs2_glock_nq_m(num_gh, ghs); |
| 593 | if (error) |
| 594 | goto out_uninit; |
| 595 | |
| 596 | /* Check out the old directory */ |
| 597 | |
| 598 | error = gfs2_unlink_ok(odip, &odentry->d_name, ip); |
| 599 | if (error) |
| 600 | goto out_gunlock; |
| 601 | |
| 602 | /* Check out the new directory */ |
| 603 | |
| 604 | if (nip) { |
| 605 | error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip); |
| 606 | if (error) |
| 607 | goto out_gunlock; |
| 608 | |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 609 | if (S_ISDIR(nip->i_inode.i_mode)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 610 | if (nip->i_di.di_entries < 2) { |
| 611 | if (gfs2_consist_inode(nip)) |
Steven Whitehouse | 4cc14f0 | 2006-10-31 19:00:24 -0500 | [diff] [blame] | 612 | gfs2_dinode_print(nip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 613 | error = -EIO; |
| 614 | goto out_gunlock; |
| 615 | } |
| 616 | if (nip->i_di.di_entries > 2) { |
| 617 | error = -ENOTEMPTY; |
| 618 | goto out_gunlock; |
| 619 | } |
| 620 | } |
| 621 | } else { |
Steven Whitehouse | faf450e | 2006-06-22 10:59:10 -0400 | [diff] [blame] | 622 | error = permission(ndir, MAY_WRITE | MAY_EXEC, NULL); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 623 | if (error) |
| 624 | goto out_gunlock; |
| 625 | |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 626 | error = gfs2_dir_search(ndir, &ndentry->d_name, NULL, NULL); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 627 | switch (error) { |
| 628 | case -ENOENT: |
| 629 | error = 0; |
| 630 | break; |
| 631 | case 0: |
| 632 | error = -EEXIST; |
| 633 | default: |
| 634 | goto out_gunlock; |
| 635 | }; |
| 636 | |
| 637 | if (odip != ndip) { |
Steven Whitehouse | 4f56110 | 2006-11-01 14:04:17 -0500 | [diff] [blame] | 638 | if (!ndip->i_inode.i_nlink) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 639 | error = -EINVAL; |
| 640 | goto out_gunlock; |
| 641 | } |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 642 | if (ndip->i_di.di_entries == (u32)-1) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 643 | error = -EFBIG; |
| 644 | goto out_gunlock; |
| 645 | } |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 646 | if (S_ISDIR(ip->i_inode.i_mode) && |
Steven Whitehouse | 4f56110 | 2006-11-01 14:04:17 -0500 | [diff] [blame] | 647 | ndip->i_inode.i_nlink == (u32)-1) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 648 | error = -EMLINK; |
| 649 | goto out_gunlock; |
| 650 | } |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | /* Check out the dir to be renamed */ |
| 655 | |
| 656 | if (dir_rename) { |
Steven Whitehouse | faf450e | 2006-06-22 10:59:10 -0400 | [diff] [blame] | 657 | error = permission(odentry->d_inode, MAY_WRITE, NULL); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 658 | if (error) |
| 659 | goto out_gunlock; |
| 660 | } |
| 661 | |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 662 | alloc_required = error = gfs2_diradd_alloc_required(ndir, &ndentry->d_name); |
| 663 | if (error < 0) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 664 | goto out_gunlock; |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 665 | error = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 666 | |
| 667 | if (alloc_required) { |
| 668 | struct gfs2_alloc *al = gfs2_alloc_get(ndip); |
| 669 | |
| 670 | error = gfs2_quota_lock(ndip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); |
| 671 | if (error) |
| 672 | goto out_alloc; |
| 673 | |
Steven Whitehouse | 2933f92 | 2006-11-01 13:23:29 -0500 | [diff] [blame] | 674 | error = gfs2_quota_check(ndip, ndip->i_inode.i_uid, ndip->i_inode.i_gid); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 675 | if (error) |
| 676 | goto out_gunlock_q; |
| 677 | |
| 678 | al->al_requested = sdp->sd_max_dirres; |
| 679 | |
| 680 | error = gfs2_inplace_reserve(ndip); |
| 681 | if (error) |
| 682 | goto out_gunlock_q; |
| 683 | |
Steven Whitehouse | fe1bded | 2006-04-18 10:09:15 -0400 | [diff] [blame] | 684 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 685 | al->al_rgd->rd_ri.ri_length + |
| 686 | 4 * RES_DINODE + 4 * RES_LEAF + |
S. Wendy Cheng | 87d21e0 | 2007-01-18 16:07:03 -0500 | [diff] [blame^] | 687 | RES_STATFS + RES_QUOTA + 4, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 688 | if (error) |
| 689 | goto out_ipreserv; |
| 690 | } else { |
| 691 | error = gfs2_trans_begin(sdp, 4 * RES_DINODE + |
S. Wendy Cheng | 87d21e0 | 2007-01-18 16:07:03 -0500 | [diff] [blame^] | 692 | 5 * RES_LEAF + 4, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 693 | if (error) |
| 694 | goto out_gunlock; |
| 695 | } |
| 696 | |
| 697 | /* Remove the target file, if it exists */ |
| 698 | |
| 699 | if (nip) { |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 700 | if (S_ISDIR(nip->i_inode.i_mode)) |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 701 | error = gfs2_rmdiri(ndip, &ndentry->d_name, nip); |
| 702 | else { |
| 703 | error = gfs2_dir_del(ndip, &ndentry->d_name); |
| 704 | if (error) |
| 705 | goto out_end_trans; |
S. Wendy Cheng | 87d21e0 | 2007-01-18 16:07:03 -0500 | [diff] [blame^] | 706 | error = gfs2_change_nlink(nip, -1); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 707 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 708 | if (error) |
| 709 | goto out_end_trans; |
| 710 | } |
| 711 | |
| 712 | if (dir_rename) { |
| 713 | struct qstr name; |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 714 | gfs2_str2qstr(&name, ".."); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 715 | |
| 716 | error = gfs2_change_nlink(ndip, +1); |
| 717 | if (error) |
| 718 | goto out_end_trans; |
| 719 | error = gfs2_change_nlink(odip, -1); |
| 720 | if (error) |
| 721 | goto out_end_trans; |
| 722 | |
| 723 | error = gfs2_dir_mvino(ip, &name, &ndip->i_num, DT_DIR); |
| 724 | if (error) |
| 725 | goto out_end_trans; |
| 726 | } else { |
| 727 | struct buffer_head *dibh; |
| 728 | error = gfs2_meta_inode_buffer(ip, &dibh); |
| 729 | if (error) |
| 730 | goto out_end_trans; |
Steven Whitehouse | 1a7b1ee | 2006-11-01 14:35:17 -0500 | [diff] [blame] | 731 | ip->i_inode.i_ctime.tv_sec = get_seconds(); |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 732 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
Steven Whitehouse | 539e5d6 | 2006-10-31 15:07:05 -0500 | [diff] [blame] | 733 | gfs2_dinode_out(ip, dibh->b_data); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 734 | brelse(dibh); |
| 735 | } |
| 736 | |
| 737 | error = gfs2_dir_del(odip, &odentry->d_name); |
| 738 | if (error) |
| 739 | goto out_end_trans; |
| 740 | |
Steven Whitehouse | c752666 | 2006-03-20 12:30:04 -0500 | [diff] [blame] | 741 | error = gfs2_dir_add(ndir, &ndentry->d_name, &ip->i_num, |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 742 | IF2DT(ip->i_inode.i_mode)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 743 | if (error) |
| 744 | goto out_end_trans; |
| 745 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 746 | out_end_trans: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 747 | gfs2_trans_end(sdp); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 748 | out_ipreserv: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 749 | if (alloc_required) |
| 750 | gfs2_inplace_release(ndip); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 751 | out_gunlock_q: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 752 | if (alloc_required) |
| 753 | gfs2_quota_unlock(ndip); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 754 | out_alloc: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 755 | if (alloc_required) |
| 756 | gfs2_alloc_put(ndip); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 757 | out_gunlock: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 758 | gfs2_glock_dq_m(num_gh, ghs); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 759 | out_uninit: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 760 | for (x = 0; x < num_gh; x++) |
| 761 | gfs2_holder_uninit(ghs + x); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 762 | out_gunlock_r: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 763 | if (dir_rename) |
| 764 | gfs2_glock_dq_uninit(&r_gh); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 765 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 766 | return error; |
| 767 | } |
| 768 | |
| 769 | /** |
| 770 | * gfs2_readlink - Read the value of a symlink |
| 771 | * @dentry: the symlink |
| 772 | * @buf: the buffer to read the symlink data into |
| 773 | * @size: the size of the buffer |
| 774 | * |
| 775 | * Returns: errno |
| 776 | */ |
| 777 | |
| 778 | static int gfs2_readlink(struct dentry *dentry, char __user *user_buf, |
| 779 | int user_size) |
| 780 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 781 | struct gfs2_inode *ip = GFS2_I(dentry->d_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 782 | char array[GFS2_FAST_NAME_SIZE], *buf = array; |
| 783 | unsigned int len = GFS2_FAST_NAME_SIZE; |
| 784 | int error; |
| 785 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 786 | error = gfs2_readlinki(ip, &buf, &len); |
| 787 | if (error) |
| 788 | return error; |
| 789 | |
| 790 | if (user_size > len - 1) |
| 791 | user_size = len - 1; |
| 792 | |
| 793 | if (copy_to_user(user_buf, buf, user_size)) |
| 794 | error = -EFAULT; |
| 795 | else |
| 796 | error = user_size; |
| 797 | |
| 798 | if (buf != array) |
| 799 | kfree(buf); |
| 800 | |
| 801 | return error; |
| 802 | } |
| 803 | |
| 804 | /** |
| 805 | * gfs2_follow_link - Follow a symbolic link |
| 806 | * @dentry: The dentry of the link |
| 807 | * @nd: Data that we pass to vfs_follow_link() |
| 808 | * |
| 809 | * This can handle symlinks of any size. It is optimised for symlinks |
| 810 | * under GFS2_FAST_NAME_SIZE. |
| 811 | * |
| 812 | * Returns: 0 on success or error code |
| 813 | */ |
| 814 | |
| 815 | static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd) |
| 816 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 817 | struct gfs2_inode *ip = GFS2_I(dentry->d_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 818 | char array[GFS2_FAST_NAME_SIZE], *buf = array; |
| 819 | unsigned int len = GFS2_FAST_NAME_SIZE; |
| 820 | int error; |
| 821 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 822 | error = gfs2_readlinki(ip, &buf, &len); |
| 823 | if (!error) { |
| 824 | error = vfs_follow_link(nd, buf); |
| 825 | if (buf != array) |
| 826 | kfree(buf); |
| 827 | } |
| 828 | |
| 829 | return ERR_PTR(error); |
| 830 | } |
| 831 | |
| 832 | /** |
| 833 | * gfs2_permission - |
| 834 | * @inode: |
| 835 | * @mask: |
| 836 | * @nd: passed from Linux VFS, ignored by us |
| 837 | * |
Steven Whitehouse | 300c7d7 | 2006-11-27 09:55:28 -0500 | [diff] [blame] | 838 | * This may be called from the VFS directly, or from within GFS2 with the |
| 839 | * inode locked, so we look to see if the glock is already locked and only |
| 840 | * lock the glock if its not already been done. |
| 841 | * |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 842 | * Returns: errno |
| 843 | */ |
| 844 | |
| 845 | static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd) |
| 846 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 847 | struct gfs2_inode *ip = GFS2_I(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 848 | struct gfs2_holder i_gh; |
| 849 | int error; |
Steven Whitehouse | 300c7d7 | 2006-11-27 09:55:28 -0500 | [diff] [blame] | 850 | int unlock = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 851 | |
Steven Whitehouse | 300c7d7 | 2006-11-27 09:55:28 -0500 | [diff] [blame] | 852 | if (gfs2_glock_is_locked_by_me(ip->i_gl) == 0) { |
| 853 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh); |
| 854 | if (error) |
| 855 | return error; |
| 856 | unlock = 1; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 857 | } |
| 858 | |
Steven Whitehouse | 77386e1 | 2006-11-29 10:41:49 -0500 | [diff] [blame] | 859 | error = generic_permission(inode, mask, gfs2_check_acl); |
Steven Whitehouse | 300c7d7 | 2006-11-27 09:55:28 -0500 | [diff] [blame] | 860 | if (unlock) |
| 861 | gfs2_glock_dq_uninit(&i_gh); |
| 862 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 863 | return error; |
| 864 | } |
| 865 | |
| 866 | static int setattr_size(struct inode *inode, struct iattr *attr) |
| 867 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 868 | struct gfs2_inode *ip = GFS2_I(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 869 | int error; |
| 870 | |
| 871 | if (attr->ia_size != ip->i_di.di_size) { |
| 872 | error = vmtruncate(inode, attr->ia_size); |
| 873 | if (error) |
| 874 | return error; |
| 875 | } |
| 876 | |
Steven Whitehouse | aa6a85a | 2006-01-24 10:37:06 +0000 | [diff] [blame] | 877 | error = gfs2_truncatei(ip, attr->ia_size); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 878 | if (error) |
| 879 | return error; |
| 880 | |
| 881 | return error; |
| 882 | } |
| 883 | |
| 884 | static int setattr_chown(struct inode *inode, struct iattr *attr) |
| 885 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 886 | struct gfs2_inode *ip = GFS2_I(inode); |
| 887 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 888 | struct buffer_head *dibh; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 889 | u32 ouid, ogid, nuid, ngid; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 890 | int error; |
| 891 | |
Steven Whitehouse | 2933f92 | 2006-11-01 13:23:29 -0500 | [diff] [blame] | 892 | ouid = inode->i_uid; |
| 893 | ogid = inode->i_gid; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 894 | nuid = attr->ia_uid; |
| 895 | ngid = attr->ia_gid; |
| 896 | |
| 897 | if (!(attr->ia_valid & ATTR_UID) || ouid == nuid) |
| 898 | ouid = nuid = NO_QUOTA_CHANGE; |
| 899 | if (!(attr->ia_valid & ATTR_GID) || ogid == ngid) |
| 900 | ogid = ngid = NO_QUOTA_CHANGE; |
| 901 | |
| 902 | gfs2_alloc_get(ip); |
| 903 | |
| 904 | error = gfs2_quota_lock(ip, nuid, ngid); |
| 905 | if (error) |
| 906 | goto out_alloc; |
| 907 | |
| 908 | if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) { |
| 909 | error = gfs2_quota_check(ip, nuid, ngid); |
| 910 | if (error) |
| 911 | goto out_gunlock_q; |
| 912 | } |
| 913 | |
| 914 | error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0); |
| 915 | if (error) |
| 916 | goto out_gunlock_q; |
| 917 | |
| 918 | error = gfs2_meta_inode_buffer(ip, &dibh); |
| 919 | if (error) |
| 920 | goto out_end_trans; |
| 921 | |
| 922 | error = inode_setattr(inode, attr); |
| 923 | gfs2_assert_warn(sdp, !error); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 924 | |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 925 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
Steven Whitehouse | 539e5d6 | 2006-10-31 15:07:05 -0500 | [diff] [blame] | 926 | gfs2_dinode_out(ip, dibh->b_data); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 927 | brelse(dibh); |
| 928 | |
| 929 | if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) { |
Steven Whitehouse | af18ddb8 | 2006-06-24 15:42:21 -0400 | [diff] [blame] | 930 | gfs2_quota_change(ip, -ip->i_di.di_blocks, ouid, ogid); |
| 931 | gfs2_quota_change(ip, ip->i_di.di_blocks, nuid, ngid); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 932 | } |
| 933 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 934 | out_end_trans: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 935 | gfs2_trans_end(sdp); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 936 | out_gunlock_q: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 937 | gfs2_quota_unlock(ip); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 938 | out_alloc: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 939 | gfs2_alloc_put(ip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 940 | return error; |
| 941 | } |
| 942 | |
| 943 | /** |
| 944 | * gfs2_setattr - Change attributes on an inode |
| 945 | * @dentry: The dentry which is changing |
| 946 | * @attr: The structure describing the change |
| 947 | * |
| 948 | * The VFS layer wants to change one or more of an inodes attributes. Write |
| 949 | * that change out to disk. |
| 950 | * |
| 951 | * Returns: errno |
| 952 | */ |
| 953 | |
| 954 | static int gfs2_setattr(struct dentry *dentry, struct iattr *attr) |
| 955 | { |
| 956 | struct inode *inode = dentry->d_inode; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 957 | struct gfs2_inode *ip = GFS2_I(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 958 | struct gfs2_holder i_gh; |
| 959 | int error; |
| 960 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 961 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); |
| 962 | if (error) |
| 963 | return error; |
| 964 | |
| 965 | error = -EPERM; |
| 966 | if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
| 967 | goto out; |
| 968 | |
| 969 | error = inode_change_ok(inode, attr); |
| 970 | if (error) |
| 971 | goto out; |
| 972 | |
| 973 | if (attr->ia_valid & ATTR_SIZE) |
| 974 | error = setattr_size(inode, attr); |
| 975 | else if (attr->ia_valid & (ATTR_UID | ATTR_GID)) |
| 976 | error = setattr_chown(inode, attr); |
| 977 | else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode)) |
| 978 | error = gfs2_acl_chmod(ip, attr); |
| 979 | else |
| 980 | error = gfs2_setattr_simple(ip, attr); |
| 981 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 982 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 983 | gfs2_glock_dq_uninit(&i_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 984 | if (!error) |
| 985 | mark_inode_dirty(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 986 | return error; |
| 987 | } |
| 988 | |
| 989 | /** |
| 990 | * gfs2_getattr - Read out an inode's attributes |
Steven Whitehouse | 26c1a57 | 2006-09-04 15:32:10 -0400 | [diff] [blame] | 991 | * @mnt: The vfsmount the inode is being accessed from |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 992 | * @dentry: The dentry to stat |
| 993 | * @stat: The inode's stats |
| 994 | * |
Steven Whitehouse | dcf3dd8 | 2006-11-27 10:12:05 -0500 | [diff] [blame] | 995 | * This may be called from the VFS directly, or from within GFS2 with the |
| 996 | * inode locked, so we look to see if the glock is already locked and only |
| 997 | * lock the glock if its not already been done. Note that its the NFS |
| 998 | * readdirplus operation which causes this to be called (from filldir) |
| 999 | * with the glock already held. |
| 1000 | * |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1001 | * Returns: errno |
| 1002 | */ |
| 1003 | |
| 1004 | static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, |
| 1005 | struct kstat *stat) |
| 1006 | { |
| 1007 | struct inode *inode = dentry->d_inode; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1008 | struct gfs2_inode *ip = GFS2_I(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1009 | struct gfs2_holder gh; |
| 1010 | int error; |
Steven Whitehouse | dcf3dd8 | 2006-11-27 10:12:05 -0500 | [diff] [blame] | 1011 | int unlock = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1012 | |
Steven Whitehouse | dcf3dd8 | 2006-11-27 10:12:05 -0500 | [diff] [blame] | 1013 | if (gfs2_glock_is_locked_by_me(ip->i_gl) == 0) { |
| 1014 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh); |
| 1015 | if (error) |
| 1016 | return error; |
| 1017 | unlock = 1; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
Steven Whitehouse | dcf3dd8 | 2006-11-27 10:12:05 -0500 | [diff] [blame] | 1020 | generic_fillattr(inode, stat); |
| 1021 | if (unlock); |
| 1022 | gfs2_glock_dq_uninit(&gh); |
| 1023 | |
| 1024 | return 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | static int gfs2_setxattr(struct dentry *dentry, const char *name, |
| 1028 | const void *data, size_t size, int flags) |
| 1029 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1030 | struct inode *inode = dentry->d_inode; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1031 | struct gfs2_ea_request er; |
| 1032 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1033 | memset(&er, 0, sizeof(struct gfs2_ea_request)); |
| 1034 | er.er_type = gfs2_ea_name2type(name, &er.er_name); |
| 1035 | if (er.er_type == GFS2_EATYPE_UNUSED) |
| 1036 | return -EOPNOTSUPP; |
| 1037 | er.er_data = (char *)data; |
| 1038 | er.er_name_len = strlen(er.er_name); |
| 1039 | er.er_data_len = size; |
| 1040 | er.er_flags = flags; |
| 1041 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1042 | gfs2_assert_warn(GFS2_SB(inode), !(er.er_flags & GFS2_ERF_MODE)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1043 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1044 | return gfs2_ea_set(GFS2_I(inode), &er); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name, |
| 1048 | void *data, size_t size) |
| 1049 | { |
| 1050 | struct gfs2_ea_request er; |
| 1051 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1052 | memset(&er, 0, sizeof(struct gfs2_ea_request)); |
| 1053 | er.er_type = gfs2_ea_name2type(name, &er.er_name); |
| 1054 | if (er.er_type == GFS2_EATYPE_UNUSED) |
| 1055 | return -EOPNOTSUPP; |
| 1056 | er.er_data = data; |
| 1057 | er.er_name_len = strlen(er.er_name); |
| 1058 | er.er_data_len = size; |
| 1059 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1060 | return gfs2_ea_get(GFS2_I(dentry->d_inode), &er); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size) |
| 1064 | { |
| 1065 | struct gfs2_ea_request er; |
| 1066 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1067 | memset(&er, 0, sizeof(struct gfs2_ea_request)); |
| 1068 | er.er_data = (size) ? buffer : NULL; |
| 1069 | er.er_data_len = size; |
| 1070 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1071 | return gfs2_ea_list(GFS2_I(dentry->d_inode), &er); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | static int gfs2_removexattr(struct dentry *dentry, const char *name) |
| 1075 | { |
| 1076 | struct gfs2_ea_request er; |
| 1077 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1078 | memset(&er, 0, sizeof(struct gfs2_ea_request)); |
| 1079 | er.er_type = gfs2_ea_name2type(name, &er.er_name); |
| 1080 | if (er.er_type == GFS2_EATYPE_UNUSED) |
| 1081 | return -EOPNOTSUPP; |
| 1082 | er.er_name_len = strlen(er.er_name); |
| 1083 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1084 | return gfs2_ea_remove(GFS2_I(dentry->d_inode), &er); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | struct inode_operations gfs2_file_iops = { |
| 1088 | .permission = gfs2_permission, |
| 1089 | .setattr = gfs2_setattr, |
| 1090 | .getattr = gfs2_getattr, |
| 1091 | .setxattr = gfs2_setxattr, |
| 1092 | .getxattr = gfs2_getxattr, |
| 1093 | .listxattr = gfs2_listxattr, |
| 1094 | .removexattr = gfs2_removexattr, |
| 1095 | }; |
| 1096 | |
| 1097 | struct inode_operations gfs2_dev_iops = { |
| 1098 | .permission = gfs2_permission, |
| 1099 | .setattr = gfs2_setattr, |
| 1100 | .getattr = gfs2_getattr, |
| 1101 | .setxattr = gfs2_setxattr, |
| 1102 | .getxattr = gfs2_getxattr, |
| 1103 | .listxattr = gfs2_listxattr, |
| 1104 | .removexattr = gfs2_removexattr, |
| 1105 | }; |
| 1106 | |
| 1107 | struct inode_operations gfs2_dir_iops = { |
| 1108 | .create = gfs2_create, |
| 1109 | .lookup = gfs2_lookup, |
| 1110 | .link = gfs2_link, |
| 1111 | .unlink = gfs2_unlink, |
| 1112 | .symlink = gfs2_symlink, |
| 1113 | .mkdir = gfs2_mkdir, |
| 1114 | .rmdir = gfs2_rmdir, |
| 1115 | .mknod = gfs2_mknod, |
| 1116 | .rename = gfs2_rename, |
| 1117 | .permission = gfs2_permission, |
| 1118 | .setattr = gfs2_setattr, |
| 1119 | .getattr = gfs2_getattr, |
| 1120 | .setxattr = gfs2_setxattr, |
| 1121 | .getxattr = gfs2_getxattr, |
| 1122 | .listxattr = gfs2_listxattr, |
| 1123 | .removexattr = gfs2_removexattr, |
| 1124 | }; |
| 1125 | |
| 1126 | struct inode_operations gfs2_symlink_iops = { |
| 1127 | .readlink = gfs2_readlink, |
| 1128 | .follow_link = gfs2_follow_link, |
| 1129 | .permission = gfs2_permission, |
| 1130 | .setattr = gfs2_setattr, |
| 1131 | .getattr = gfs2_getattr, |
| 1132 | .setxattr = gfs2_setxattr, |
| 1133 | .getxattr = gfs2_getxattr, |
| 1134 | .listxattr = gfs2_listxattr, |
| 1135 | .removexattr = gfs2_removexattr, |
| 1136 | }; |
| 1137 | |