Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2002 Red Hat, Inc. All rights reserved. |
| 3 | * |
| 4 | * This software may be freely redistributed under the terms of the |
| 5 | * GNU General Public License. |
| 6 | * |
| 7 | * You should have received a copy of the GNU General Public License |
| 8 | * along with this program; if not, write to the Free Software |
| 9 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 10 | * |
David Woodhouse | 44d1b98 | 2008-06-05 22:46:18 -0700 | [diff] [blame] | 11 | * Authors: David Woodhouse <dwmw2@infradead.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * David Howells <dhowells@redhat.com> |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/slab.h> |
| 20 | #include <linux/fs.h> |
| 21 | #include <linux/pagemap.h> |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 22 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include "internal.h" |
| 24 | |
| 25 | struct afs_iget_data { |
| 26 | struct afs_fid fid; |
| 27 | struct afs_volume *volume; /* volume on which resides */ |
| 28 | }; |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | /* |
| 31 | * map the AFS file status to the inode member variables |
| 32 | */ |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 33 | static int afs_inode_map_status(struct afs_vnode *vnode, struct key *key) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { |
| 35 | struct inode *inode = AFS_VNODE_TO_I(vnode); |
| 36 | |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 37 | _debug("FS: ft=%d lk=%d sz=%llu ver=%Lu mod=%hu", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | vnode->status.type, |
| 39 | vnode->status.nlink, |
David S. Miller | ba3e0e1 | 2007-04-26 16:06:22 -0700 | [diff] [blame] | 40 | (unsigned long long) vnode->status.size, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 41 | vnode->status.data_version, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | vnode->status.mode); |
| 43 | |
| 44 | switch (vnode->status.type) { |
| 45 | case AFS_FTYPE_FILE: |
| 46 | inode->i_mode = S_IFREG | vnode->status.mode; |
| 47 | inode->i_op = &afs_file_inode_operations; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 48 | inode->i_fop = &afs_file_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | break; |
| 50 | case AFS_FTYPE_DIR: |
| 51 | inode->i_mode = S_IFDIR | vnode->status.mode; |
| 52 | inode->i_op = &afs_dir_inode_operations; |
| 53 | inode->i_fop = &afs_dir_file_operations; |
| 54 | break; |
| 55 | case AFS_FTYPE_SYMLINK: |
| 56 | inode->i_mode = S_IFLNK | vnode->status.mode; |
| 57 | inode->i_op = &page_symlink_inode_operations; |
| 58 | break; |
| 59 | default: |
| 60 | printk("kAFS: AFS vnode with undefined type\n"); |
| 61 | return -EBADMSG; |
| 62 | } |
| 63 | |
| 64 | inode->i_nlink = vnode->status.nlink; |
| 65 | inode->i_uid = vnode->status.owner; |
| 66 | inode->i_gid = 0; |
| 67 | inode->i_size = vnode->status.size; |
| 68 | inode->i_ctime.tv_sec = vnode->status.mtime_server; |
| 69 | inode->i_ctime.tv_nsec = 0; |
| 70 | inode->i_atime = inode->i_mtime = inode->i_ctime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | inode->i_blocks = 0; |
| 72 | inode->i_version = vnode->fid.unique; |
| 73 | inode->i_mapping->a_ops = &afs_fs_aops; |
| 74 | |
| 75 | /* check to see whether a symbolic link is really a mountpoint */ |
| 76 | if (vnode->status.type == AFS_FTYPE_SYMLINK) { |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 77 | afs_mntpt_check_symlink(vnode, key); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 79 | if (test_bit(AFS_VNODE_MOUNTPOINT, &vnode->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | inode->i_mode = S_IFDIR | vnode->status.mode; |
| 81 | inode->i_op = &afs_mntpt_inode_operations; |
| 82 | inode->i_fop = &afs_mntpt_file_operations; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 87 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | * iget5() comparator |
| 91 | */ |
| 92 | static int afs_iget5_test(struct inode *inode, void *opaque) |
| 93 | { |
| 94 | struct afs_iget_data *data = opaque; |
| 95 | |
| 96 | return inode->i_ino == data->fid.vnode && |
| 97 | inode->i_version == data->fid.unique; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 98 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | /* |
| 101 | * iget5() inode initialiser |
| 102 | */ |
| 103 | static int afs_iget5_set(struct inode *inode, void *opaque) |
| 104 | { |
| 105 | struct afs_iget_data *data = opaque; |
| 106 | struct afs_vnode *vnode = AFS_FS_I(inode); |
| 107 | |
| 108 | inode->i_ino = data->fid.vnode; |
| 109 | inode->i_version = data->fid.unique; |
| 110 | vnode->fid = data->fid; |
| 111 | vnode->volume = data->volume; |
| 112 | |
| 113 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 114 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | /* |
| 117 | * inode retrieval |
| 118 | */ |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 119 | struct inode *afs_iget(struct super_block *sb, struct key *key, |
| 120 | struct afs_fid *fid, struct afs_file_status *status, |
| 121 | struct afs_callback *cb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
| 123 | struct afs_iget_data data = { .fid = *fid }; |
| 124 | struct afs_super_info *as; |
| 125 | struct afs_vnode *vnode; |
| 126 | struct inode *inode; |
| 127 | int ret; |
| 128 | |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 129 | _enter(",{%x:%u.%u},,", fid->vid, fid->vnode, fid->unique); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | as = sb->s_fs_info; |
| 132 | data.volume = as->volume; |
| 133 | |
| 134 | inode = iget5_locked(sb, fid->vnode, afs_iget5_test, afs_iget5_set, |
| 135 | &data); |
| 136 | if (!inode) { |
| 137 | _leave(" = -ENOMEM"); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 138 | return ERR_PTR(-ENOMEM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
| 140 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 141 | _debug("GOT INODE %p { vl=%x vn=%x, u=%x }", |
| 142 | inode, fid->vid, fid->vnode, fid->unique); |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | vnode = AFS_FS_I(inode); |
| 145 | |
| 146 | /* deal with an existing inode */ |
| 147 | if (!(inode->i_state & I_NEW)) { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 148 | _leave(" = %p", inode); |
| 149 | return inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | #ifdef AFS_CACHING_SUPPORT |
| 153 | /* set up caching before reading the status, as fetch-status reads the |
| 154 | * first page of symlinks to see if they're really mntpts */ |
| 155 | cachefs_acquire_cookie(vnode->volume->cache, |
| 156 | NULL, |
| 157 | vnode, |
| 158 | &vnode->cache); |
| 159 | #endif |
| 160 | |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 161 | if (!status) { |
| 162 | /* it's a remotely extant inode */ |
| 163 | set_bit(AFS_VNODE_CB_BROKEN, &vnode->flags); |
| 164 | ret = afs_vnode_fetch_status(vnode, NULL, key); |
| 165 | if (ret < 0) |
| 166 | goto bad_inode; |
| 167 | } else { |
| 168 | /* it's an inode we just created */ |
| 169 | memcpy(&vnode->status, status, sizeof(vnode->status)); |
| 170 | |
| 171 | if (!cb) { |
| 172 | /* it's a symlink we just created (the fileserver |
| 173 | * didn't give us a callback) */ |
| 174 | vnode->cb_version = 0; |
| 175 | vnode->cb_expiry = 0; |
| 176 | vnode->cb_type = 0; |
| 177 | vnode->cb_expires = get_seconds(); |
| 178 | } else { |
| 179 | vnode->cb_version = cb->version; |
| 180 | vnode->cb_expiry = cb->expiry; |
| 181 | vnode->cb_type = cb->type; |
| 182 | vnode->cb_expires = vnode->cb_expiry + get_seconds(); |
| 183 | } |
| 184 | } |
| 185 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 186 | ret = afs_inode_map_status(vnode, key); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 187 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | goto bad_inode; |
| 189 | |
| 190 | /* success */ |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 191 | clear_bit(AFS_VNODE_UNSET, &vnode->flags); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 192 | inode->i_flags |= S_NOATIME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | unlock_new_inode(inode); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 194 | _leave(" = %p [CB { v=%u t=%u }]", inode, vnode->cb_version, vnode->cb_type); |
| 195 | return inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
| 197 | /* failure */ |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 198 | bad_inode: |
David Howells | aa7fa24 | 2008-02-07 00:15:28 -0800 | [diff] [blame] | 199 | iget_failed(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | _leave(" = %d [bad]", ret); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 201 | return ERR_PTR(ret); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 202 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | /* |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 205 | * mark the data attached to an inode as obsolete due to a write on the server |
| 206 | * - might also want to ditch all the outstanding writes and dirty pages |
| 207 | */ |
| 208 | void afs_zap_data(struct afs_vnode *vnode) |
| 209 | { |
David Howells | 0f300ca | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 210 | _enter("{%x:%u}", vnode->fid.vid, vnode->fid.vnode); |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 211 | |
| 212 | /* nuke all the non-dirty pages that aren't locked, mapped or being |
David Howells | 0f300ca | 2007-05-10 22:22:20 -0700 | [diff] [blame] | 213 | * written back in a regular file and completely discard the pages in a |
| 214 | * directory or symlink */ |
| 215 | if (S_ISREG(vnode->vfs_inode.i_mode)) |
| 216 | invalidate_remote_inode(&vnode->vfs_inode); |
| 217 | else |
| 218 | invalidate_inode_pages2(vnode->vfs_inode.i_mapping); |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /* |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 222 | * validate a vnode/inode |
| 223 | * - there are several things we need to check |
| 224 | * - parent dir data changes (rm, rmdir, rename, mkdir, create, link, |
| 225 | * symlink) |
| 226 | * - parent dir metadata changed (security changes) |
| 227 | * - dentry data changed (write, truncate) |
| 228 | * - dentry metadata changed (security changes) |
| 229 | */ |
| 230 | int afs_validate(struct afs_vnode *vnode, struct key *key) |
| 231 | { |
| 232 | int ret; |
| 233 | |
| 234 | _enter("{v={%x:%u} fl=%lx},%x", |
| 235 | vnode->fid.vid, vnode->fid.vnode, vnode->flags, |
| 236 | key_serial(key)); |
| 237 | |
| 238 | if (vnode->cb_promised && |
| 239 | !test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags) && |
| 240 | !test_bit(AFS_VNODE_MODIFIED, &vnode->flags) && |
| 241 | !test_bit(AFS_VNODE_ZAP_DATA, &vnode->flags)) { |
| 242 | if (vnode->cb_expires < get_seconds() + 10) { |
| 243 | _debug("callback expired"); |
| 244 | set_bit(AFS_VNODE_CB_BROKEN, &vnode->flags); |
| 245 | } else { |
| 246 | goto valid; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) |
| 251 | goto valid; |
| 252 | |
| 253 | mutex_lock(&vnode->validate_lock); |
| 254 | |
| 255 | /* if the promise has expired, we need to check the server again to get |
| 256 | * a new promise - note that if the (parent) directory's metadata was |
| 257 | * changed then the security may be different and we may no longer have |
| 258 | * access */ |
| 259 | if (!vnode->cb_promised || |
| 260 | test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags)) { |
| 261 | _debug("not promised"); |
| 262 | ret = afs_vnode_fetch_status(vnode, NULL, key); |
| 263 | if (ret < 0) |
| 264 | goto error_unlock; |
| 265 | _debug("new promise [fl=%lx]", vnode->flags); |
| 266 | } |
| 267 | |
| 268 | if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) { |
| 269 | _debug("file already deleted"); |
| 270 | ret = -ESTALE; |
| 271 | goto error_unlock; |
| 272 | } |
| 273 | |
| 274 | /* if the vnode's data version number changed then its contents are |
| 275 | * different */ |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 276 | if (test_and_clear_bit(AFS_VNODE_ZAP_DATA, &vnode->flags)) |
| 277 | afs_zap_data(vnode); |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 278 | |
| 279 | clear_bit(AFS_VNODE_MODIFIED, &vnode->flags); |
| 280 | mutex_unlock(&vnode->validate_lock); |
| 281 | valid: |
| 282 | _leave(" = 0"); |
| 283 | return 0; |
| 284 | |
| 285 | error_unlock: |
| 286 | mutex_unlock(&vnode->validate_lock); |
| 287 | _leave(" = %d", ret); |
| 288 | return ret; |
| 289 | } |
| 290 | |
| 291 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | * read the attributes of an inode |
| 293 | */ |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 294 | int afs_getattr(struct vfsmount *mnt, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | struct kstat *stat) |
| 296 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | struct inode *inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
| 299 | inode = dentry->d_inode; |
| 300 | |
Jean Noel Cordenner | 7a22422 | 2008-01-28 23:58:27 -0500 | [diff] [blame] | 301 | _enter("{ ino=%lu v=%llu }", inode->i_ino, |
| 302 | (unsigned long long)inode->i_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | generic_fillattr(inode, stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 306 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | /* |
| 309 | * clear an AFS inode |
| 310 | */ |
| 311 | void afs_clear_inode(struct inode *inode) |
| 312 | { |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 313 | struct afs_permits *permits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | struct afs_vnode *vnode; |
| 315 | |
| 316 | vnode = AFS_FS_I(inode); |
| 317 | |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 318 | _enter("{%x:%u.%d} v=%u x=%u t=%u }", |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 319 | vnode->fid.vid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | vnode->fid.vnode, |
David Howells | 260a980 | 2007-04-26 15:59:35 -0700 | [diff] [blame] | 321 | vnode->fid.unique, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | vnode->cb_version, |
| 323 | vnode->cb_expiry, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 324 | vnode->cb_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 326 | _debug("CLEAR INODE %p", inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 328 | ASSERTCMP(inode->i_ino, ==, vnode->fid.vnode); |
| 329 | |
| 330 | afs_give_up_callback(vnode); |
| 331 | |
| 332 | if (vnode->server) { |
| 333 | spin_lock(&vnode->server->fs_lock); |
| 334 | rb_erase(&vnode->server_rb, &vnode->server->fs_vnodes); |
| 335 | spin_unlock(&vnode->server->fs_lock); |
| 336 | afs_put_server(vnode->server); |
| 337 | vnode->server = NULL; |
| 338 | } |
| 339 | |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 340 | ASSERT(list_empty(&vnode->writebacks)); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 341 | ASSERT(!vnode->cb_promised); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
| 343 | #ifdef AFS_CACHING_SUPPORT |
| 344 | cachefs_relinquish_cookie(vnode->cache, 0); |
| 345 | vnode->cache = NULL; |
| 346 | #endif |
| 347 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 348 | mutex_lock(&vnode->permits_lock); |
| 349 | permits = vnode->permits; |
| 350 | rcu_assign_pointer(vnode->permits, NULL); |
| 351 | mutex_unlock(&vnode->permits_lock); |
| 352 | if (permits) |
| 353 | call_rcu(&permits->rcu, afs_zap_permits); |
| 354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 356 | } |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 357 | |
| 358 | /* |
| 359 | * set the attributes of an inode |
| 360 | */ |
| 361 | int afs_setattr(struct dentry *dentry, struct iattr *attr) |
| 362 | { |
| 363 | struct afs_vnode *vnode = AFS_FS_I(dentry->d_inode); |
| 364 | struct key *key; |
| 365 | int ret; |
| 366 | |
| 367 | _enter("{%x:%u},{n=%s},%x", |
| 368 | vnode->fid.vid, vnode->fid.vnode, dentry->d_name.name, |
| 369 | attr->ia_valid); |
| 370 | |
| 371 | if (!(attr->ia_valid & (ATTR_SIZE | ATTR_MODE | ATTR_UID | ATTR_GID | |
| 372 | ATTR_MTIME))) { |
| 373 | _leave(" = 0 [unsupported]"); |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | /* flush any dirty data outstanding on a regular file */ |
| 378 | if (S_ISREG(vnode->vfs_inode.i_mode)) { |
| 379 | filemap_write_and_wait(vnode->vfs_inode.i_mapping); |
| 380 | afs_writeback_all(vnode); |
| 381 | } |
| 382 | |
| 383 | if (attr->ia_valid & ATTR_FILE) { |
| 384 | key = attr->ia_file->private_data; |
| 385 | } else { |
| 386 | key = afs_request_key(vnode->volume->cell); |
| 387 | if (IS_ERR(key)) { |
| 388 | ret = PTR_ERR(key); |
| 389 | goto error; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | ret = afs_vnode_setattr(vnode, key, attr); |
| 394 | if (!(attr->ia_valid & ATTR_FILE)) |
| 395 | key_put(key); |
| 396 | |
| 397 | error: |
| 398 | _leave(" = %d", ret); |
| 399 | return ret; |
| 400 | } |