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