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