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