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